Multi-tenant database isolation method, device and electronic device

By setting up tenant tables and data source tables in the multi-tenant management module, and determining the second database corresponding to the target tenant based on the multi-tenant management module, the traditional multi-tenant database isolation method cannot take into account data isolation security and data maintenance convenience. The problem has achieved the convenience of data security isolation and data maintenance.

CN112906054BActive Publication Date: 2025-02-14GUANGDIAN INFORMATION DEV CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110273444.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-12
Publication Date
2025-02-14
Estimated Expiration
2041-03-12

AI Technical Summary

Technical Problem

Traditional multi-tenant database isolation methods cannot take into account the security of data isolation and the convenience of data maintenance.

Method used

By setting up a tenant table and a data source table in the multi-tenant management module, each data source corresponds to a database, and when receiving user business requests, the second database corresponding to the target tenant is determined according to the multi-tenant management module to ensure that the second database and The first database structure is consistent, and the operating system is switched to connect to the second database.

Benefits of technology

It realizes data security isolation between different tenants, and maintains database data information of different tenants through metadata tables, improving the convenience of data maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112906054B_ABST
    Figure CN112906054B_ABST
Patent Text Reader

Abstract

The present invention provides a multi-tenant database isolation method, device and electronic device, the method comprising: if a user's business request is received, determining the target tenant corresponding to the tenant according to a preset multi-tenant management module; wherein the multi-tenant management module runs on a designated operating system, and the designated operating system is connected to a first database in communication; the multi-tenant management module is used to manage the logical relationship between multiple databases, each database corresponding to a tenant; determining the second database corresponding to the target tenant according to the multi-tenant management module; switching the designated operating system from the first database to the second database. An embodiment of the present invention provides a multi-tenant database isolation method, which isolates databases and manages the logical relationship between databases to provide a multi-tenant database isolation method that can take into account tenants' security requirements for data isolation and convenience of data maintenance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of multi-tenant application technology, and in particular to a multi-tenant database isolation method, device and electronic equipment. Background Art

[0002] Multi-tenancy technology is a software architecture technology and also a Software as a Service (SaaS). This technology implements how to share the same system or program components in a multi-tenant environment while ensuring data isolation between tenants. Since multi-tenancy technology allows multiple tenants to share an application or computing environment, it can effectively reduce the cost of environment construction for suppliers, including the hardware system itself, operating system, and corresponding software authorization.

[0003] There are two main isolation schemes for traditional multi-tenant architectures. One is a data isolation scheme based on the structure of a relational database, which has disadvantages such as low isolation level and poor security. The other is a scheme driven by metadata and dynamically compiled to generate a multi-tenant architecture at runtime. This scheme requires the introduction of various data caching technologies, which has disadvantages such as non-intuitive data storage and difficult data maintenance.

[0004] In general, the traditional multi-tenant database isolation method cannot take into account both the tenants' security needs for data isolation and the convenience of data maintenance. Summary of the invention

[0005] In view of this, an object of the present invention is to provide a multi-tenant isolation method, device and electronic device, which can take into account both the tenants' security requirements for data isolation and the convenience of data maintenance.

[0006] In a first aspect, an embodiment of the present invention provides a multi-tenant database isolation method, which is applied to the field of multi-tenant application technology, and the method includes: if a user's business request is received, determining the target tenant corresponding to the tenant according to a preset multi-tenant management module; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is communicated with a first database; the multi-tenant management module is used to manage the logical relationship between multiple databases, each database corresponding to a tenant; determining the second database corresponding to the target tenant according to the multi-tenant management module; wherein the structure of the second database is consistent with that of the first database; and switching the specified operating system from the first database to the second database.

[0007] In combination with the first aspect, an embodiment of the present invention provides a first possible implementation of the first aspect, wherein a tenant table and a data source table are preset in the multi-tenant management module; the tenant table is used to store tenant information of the tenant, and the data source table is used to store information of the data source of the tenant, and each data source information corresponds to a database.

[0008] In combination with the first aspect, an embodiment of the present invention provides a second possible implementation of the first aspect, wherein the step of determining the target tenant corresponding to the tenant according to a preset multi-tenant management module includes: reading the target tenant corresponding to the tenant from the tenant table of the multi-tenant management module; the step of determining the second database corresponding to the target tenant according to the multi-tenant management module includes: reading information of the data source corresponding to the target tenant from the data source table of the multi-tenant management module; and determining the second database corresponding to the target tenant through the read information of the data source.

[0009] In combination with the first aspect, an embodiment of the present invention provides a third possible implementation of the first aspect, wherein the second database is pre-created in the following manner: receiving a database creation request of the target tenant; the database creation request carries basic information of the target tenant; saving the basic information of the target tenant in a preset tenant table of the multi-tenant management module; creating a data source configuration file based on the basic information of the target tenant, and registering the data source of the target tenant; saving the information of the registered data source in the preset data source table of the multi-tenant management module; creating a business database of the target tenant according to a preset database table creation statement configuration; wherein the business database includes at least one business table; initializing the business table in the business database through a preset initialization script to obtain a created second database; wherein the initialization script is obtained based on the first database.

[0010] In combination with the first aspect, an embodiment of the present invention provides a fourth possible implementation of the first aspect, wherein the initialization script is obtained in the following manner: obtaining the metadata of the business table in the first database; parsing the metadata to obtain corresponding metadata information; and generating an initialization script for the business database based on the metadata information.

[0011] In combination with the first aspect, an embodiment of the present invention provides a fifth possible implementation of the first aspect, wherein the step of obtaining the metadata of the business table in the first database includes: extracting the metadata of the business table in the first database through a pre-installed Metacat.

[0012] In combination with the first aspect, an embodiment of the present invention provides a sixth possible implementation of the first aspect, wherein, after initializing the business table in the business database through a preset initialization script to obtain a step of creating a second database, the method also includes: saving the configuration information of the second database to the database table of the multi-tenant management module; wherein the configuration information includes: the storage path, backup strategy, and access strategy of the database file.

[0013] In combination with the first aspect, an embodiment of the present invention provides a seventh possible implementation of the first aspect, wherein, after the step of parsing the metadata to obtain corresponding metadata information, the method also includes: saving the metadata information to a preset metadata table of the multi-tenant management module.

[0014] In a second aspect, an embodiment of the present invention provides a multi-tenant database isolation device, which includes: a target tenant determination module, which is used to determine the target tenant corresponding to the tenant according to a preset multi-tenant management module if a user's business request is received; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is communicated with a first database; the multi-tenant management module is used to manage the logical relationship between multiple databases, each database corresponding to a tenant; a second database determination module, which is used to determine the second database corresponding to the target tenant according to the multi-tenant management module; wherein the structure of the second database is consistent with that of the first database; and a database switching module, which is used to switch the connection of the specified operating system from the first database to the second database.

[0015] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the steps of the multi-tenant database isolation method of the first aspect and any one of the seven possible implementations of the first aspect.

[0016] The embodiments of the present invention bring the following beneficial effects:

[0017] The database isolation method, device and electronic device of multiple tenants provided by the embodiment of the present invention include: if a user's business request is received, the target tenant corresponding to the tenant is determined according to a preset multi-tenant management module; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is connected to a first database in communication; the multi-tenant management module is used to manage the logical relationship between multiple databases, and each database corresponds to a tenant; the second database corresponding to the target tenant is determined according to the multi-tenant management module; wherein the structure of the second database is consistent with that of the first database; and the specified operating system is switched from the first database to the second database. In this technology, the relationship between tenants and databases is managed by setting a multi-tenant management module. When a tenant needs to perform a business operation, the corresponding target database is determined according to the management module, and the operating system is automatically switched to the target database, thereby realizing data security isolation between different tenants. In addition, the method also sets a metadata table in the multi-tenant management module, and the metadata table is used to store metadata information of the business table in the database, so that the data information of the databases of different tenants can be uniformly maintained based on the metadata table, thereby improving the convenience of data maintenance.

[0018] Other features and advantages of the present invention will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present invention.

[0019] In order to make the above-mentioned objects, features and advantages of the present invention more clearly understood, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0021] Figure 1 A schematic diagram of a multi-tenant database isolation method provided by an embodiment of the present invention;

[0022] Figure 2 A schematic diagram of another multi-tenant database isolation method flow chart provided by an embodiment of the present invention;

[0023] Figure 3 A schematic diagram of a multi-tenant management terminal database provided in an embodiment of the present invention;

[0024] Figure 4A schematic diagram of a multi-tenant database isolation device provided by an embodiment of the present invention;

[0025] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

[0026] Icons: 41 - target tenant determination module; 42 - second database determination module; 43 - database switching module; 51 - memory; 52 - processor; 53 - bus; 54 - communication interface. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are 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 creative work are within the scope of protection of the present invention.

[0028] At present, there are two main methods for traditional multi-tenant database isolation. One is a data isolation solution based on the relational database structure, which includes three isolation methods: "independent database", "shared database, independent chart", and "shared database, shared chart, shared data table"; the other is a multi-tenant database solution driven by metadata and dynamically compiled at runtime.

[0029] Among them, the disadvantages of implementing multi-tenant database isolation through the "independent database" method are: the increase in the number of database installations, high maintenance costs and purchase costs; the disadvantages of implementing multi-tenant database isolation through the "shared database, independent chart" method are: data recovery is difficult in the event of a failure, and the process of restoring the database will involve the databases of other tenants; the disadvantages of implementing multi-tenant database isolation through the "shared database, shared chart, shared data table" method are: the data isolation level between tenants is low, security is poor, and data backup and recovery are difficult; in addition, through the "metadata-driven, runtime dynamically compiled multi-tenant database method", this method constructs a metadata-driven multi-tenant database isolation architecture. The data model of this architecture is too complex, and various complex caching technologies need to be introduced. The data storage is not intuitive and data maintenance is also difficult.

[0030] Based on this, an embodiment of the present invention provides a multi-tenant database isolation method, device and electronic device, which can be applied to the scenario of upgrading a single-tenant system to a multi-tenant system. To facilitate understanding of this embodiment, a multi-tenant database isolation method disclosed in an embodiment of the present invention is first introduced in detail.

[0031] Example 1

[0032] like Figure 1 As shown, Figure 1 A schematic diagram of a multi-tenant database isolation method provided in an embodiment of the present invention includes the following steps:

[0033] Step S101: If a business request from a user is received, a target tenant corresponding to the tenant is determined according to a preset multi-tenant management module; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is communicated with a first database; the multi-tenant management module is used to manage the logical relationship between multiple databases, and each database corresponds to a tenant.

[0034] In this embodiment, the user's service request is a user login request of the target tenant.

[0035] For example, the tenant is company a, and the employee of company a is user a1. When user a1 submits a login request, the multi-tenant management module determines that the target tenant corresponding to the tenant information is company a based on the tenant information in the login request submitted by user a1.

[0036] In one or more of the embodiments, the multi-tenant management module is a multi-tenant management terminal database, which is pre-set with databases of m top-level tenants, and the data of the databases of the m top-level tenants are isolated from each other; each database corresponding to the top-level tenant includes databases corresponding to n subordinate tenants; the data of the databases corresponding to the n subordinate tenants are isolated from each other; the top-level tenant can access the database corresponding to the subordinate tenant corresponding to it according to q access strategies; the database of each subordinate tenant corresponds one-to-one to the tenant information of the subordinate tenant.

[0037] In addition, a metadata table is set in the multi-tenant management module, and the metadata table is used to store metadata information of the business table in the database. When maintaining data, there is no need to modify the business table in the database. Only a certain metadata information of the business table in the database needs to be modified to modify the structure of the database, so that the data information of the databases of different tenants can be uniformly maintained based on the metadata table, and a logical relationship between multiple databases is established, and each database corresponds to a tenant.

[0038] Step S102: Determine a second database corresponding to the target tenant according to the multi-tenant management module; wherein the structure of the second database is consistent with that of the first database.

[0039] In this embodiment, since a metadata table is set in the multi-tenant management module, the metadata table is used to store metadata information of the business table in the database. The database corresponding to the target tenant can be maintained through the metadata information so that the structure of the second database is consistent with that of the first database.

[0040] For example, by modifying the metadata information, a structure of a database business table is set to be consistent with the structure of the business table of the first database, so that the structure of the database related to the metadata information is consistent with the structure of the first database.

[0041] Step S103: Switching the connection of the designated operating system from the first database to the second database.

[0042] In this embodiment, assuming that the designated operating system is associated with the first database, after the user's login request is submitted, the multi-tenant management module finds the database associated with the target tenant corresponding to the user, and then switches the connection of the designated operating system from the first database to the database associated with the target tenant corresponding to the user.

[0043] The multi-tenant database isolation method provided by the embodiment of the present invention comprises: if a user's business request is received, the target tenant corresponding to the tenant is determined according to a preset multi-tenant management module; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is connected to a first database in communication; the multi-tenant management module is used to manage the logical relationship between multiple databases, and each database corresponds to a tenant; the second database corresponding to the target tenant is determined according to the multi-tenant management module; wherein the structure of the second database is consistent with that of the first database; the specified operating system is switched from the first database to the second database. In the method, when the tenant needs to perform business operations, the corresponding target database is determined according to the management module, and the operating system is automatically switched to the target database, thereby realizing data security isolation between different tenants. In addition, the method also improves the convenience of data maintenance by setting a metadata table in the multi-tenant management module and uniformly maintaining the data information of databases of different tenants based on the metadata table.

[0044] Example 2

[0045] exist Figure 1 Based on the method shown in FIG. 1 , the present invention also provides another multi-tenant database isolation method, such as Figure 2 As shown, Figure 2 A schematic flow chart of another multi-tenant database isolation method provided in an embodiment of the present invention.

[0046] Step S201: If a business request from the user is received, the target tenant corresponding to the tenant is read from the tenant table of the preset multi-tenant management module; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is communicated with the first database; a tenant table and a data source table are preset in the multi-tenant management module; the tenant table is used to store the tenant information of the tenant, and the data source table is used to store the data source information of the tenant, and each data source information corresponds to a database.

[0047] In this embodiment, the multi-tenant management module is a multi-tenant management terminal database. Figure 3 Schematic diagram of a multi-tenant management terminal database provided by an embodiment of the present invention. Figure 3 As can be seen, the multi-tenant management end database includes a top-level tenant's database, and the top-level tenant's database includes databases corresponding to n subordinate tenants; the data of the n subordinate tenants' databases are completely isolated from each other; the top-level tenant can access the database of the corresponding subordinate tenant according to q access strategies; each subordinate tenant's database corresponds to the tenant information one by one; the multi-tenant management module is based on the model of the multi-tenant management end database composed of the above multiple databases. In addition, the data source of the top-level tenant can generate a second database of the top-level tenant, and the database of the top-level tenant includes the schema of n databases of the subordinate tenants, and the schema represents a database object collection, which includes various objects, such as: tables, views, stored procedures, and indexes, etc.; the database of the top-level tenant, the data source of the top-level tenant's database, and the schema of the database of the subordinate tenant include the database business table corresponding to the subordinate tenant, and the business table includes n table fields.

[0048] In one of the implementation modes, the multi-tenant management end database may also be composed of databases of m top-level tenants, the data of the databases of the m top-level tenants are isolated from each other, and the database of each top-level tenant has the same architecture as the multi-tenant management end database.

[0049] In this embodiment, a tenant table is preset in the multi-tenant management module, and the tenant table stores tenant information of all tenants; the designated operating system is a single-tenant operating system; the single-tenant operating system is communicated with the first database; the information of the data source is used to describe the information of the database of the tenant corresponding to it, so each data source corresponds to a database.

[0050] Step S202: Read the data source information corresponding to the target tenant from the data source table of the multi-tenant management module.

[0051] In one implementation manner, the information of the data source may include a data source name of a tenant, and the information of the data source corresponding to the target tenant may be determined by reading the data source name of the tenant.

[0052] Step S203: Determine the second database corresponding to the target tenant by reading the information of the data source; wherein the structure of the second database is consistent with that of the first database.

[0053] In one implementation manner, the second database corresponding to the target tenant is created in advance through the following steps A1-A6:

[0054] A1. Receive a database creation request from the target tenant; the database creation request carries basic information of the target tenant.

[0055] In this embodiment, when registering, the target tenant submits basic information of the target tenant in the designated operating system, wherein the basic information includes: the tenant name of the target tenant, the name of the second database of the target tenant, and the data source name of the second database of the target tenant.

[0056] A2. Save the basic information of the target tenant into the preset tenant table of the multi-tenant management module.

[0057] A3. Create a data source configuration file based on the basic information of the target tenant and register the data source of the target tenant.

[0058] In this embodiment, according to the basic information of the target tenant, a preset data source creation template is used to create the data source configuration file and register the data source. The registered data source is saved in the ThreadLocal software. Here, the ThreadLocal software is a tool for writing multi-threaded programs provided in the Java language software development kit. The ThreadLocal software can be used to build the target tenant's data source into a second database corresponding to the target tenant; registering the data source is to perform programming operations on the second database corresponding to the target tenant.

[0059] A4. Save the information of the registered data source to the preset data source table of the multi-tenant management module.

[0060] A5. Create a business database for the target tenant according to the preset database table creation statement configuration; wherein the business database includes at least one business table.

[0061] In this embodiment, the business database of the target tenant is created through the data source configuration file. In the data source configuration file, different databases can be distinguished according to data storage tags to execute corresponding table creation statements. The created business database includes at least one business table.

[0062] A6. Initialize the business table in the business database through a preset initialization script to obtain a created second database; wherein the initialization script is obtained based on the first database.

[0063] In this embodiment, the initialization script is obtained through the following steps B1-B3:

[0064] B1. Obtain metadata of the business table in the first database.

[0065] In one implementation, the metadata of the business table in the first database is extracted by pre-installed Metacat. Here, Metacat software provides a metadata discovery service framework for metadata discovery, metadata storage, and metadata analysis.

[0066] B2. Parse the metadata to obtain corresponding metadata information.

[0067] Here, the process of parsing the metadata to obtain corresponding metadata information can also be performed in the Metacat software.

[0068] B3. Generate an initialization script for the business database based on the metadata information.

[0069] For example, the initialization script may be a ddl.sql script.

[0070] In one or more implementation modes, after the initialization script is generated, the business table in the business database is initialized to obtain a created second database, and then the metadata information is saved in a preset metadata table of the multi-tenant management module.

[0071] In one or more embodiments, the designated operating system is a single-tenant system, and the single-tenant system is connected to the first database. First, a main data source is established in the single-tenant system, and the main data source is connected to the single-tenant system. The metadata of the business table in the database of the single-tenant system is obtained through the pre-installed Metacat software, and the metadata information such as tables and fields in the metadata is parsed, and the metadata information is saved in the preset metadata table of the multi-tenant management module. The metadata is then parsed by the Metacat software to obtain the corresponding metadata information, and the initialization script of the business database of the target tenant is generated. Finally, the business table in the business database corresponding to the target tenant is initialized by the initialization script, so that the data structure of the second database corresponding to the target tenant is consistent with that of the first database. After the initialization process of the business tables in the business databases corresponding to multiple target tenants, the process of upgrading the single-tenant system to a multi-tenant system is finally realized.

[0072] Furthermore, through the metadata table set in the multi-tenant management module, the metadata table stores the metadata information of the single-tenant system, and then the initialization script of the business database of the target tenant is generated through the above steps B1-B3. The business table in the business database corresponding to the target tenant is initialized through the initialization script, thereby establishing a logical relationship between multiple databases, so that the data information of databases of different tenants can be uniformly maintained based on the metadata table, thereby improving the convenience of data maintenance.

[0073] In one or more of the embodiments, after the above step A5, the configuration information of the second database is also saved in the database table of the multi-tenant management module; wherein the configuration information includes: the storage path, backup strategy, and access strategy of the database file. Here, the configuration information of the second database is mainly used to describe the configuration attributes of the second database. When using the database table of the multi-tenant management module, the backup strategy and the access rights of the tenant can be added.

[0074] Step S204: Switching the connection of the designated operating system from the first database to the second database.

[0075] In this embodiment, assuming that the designated operating system is associated with the first database, after the user's login request is submitted, the multi-tenant management module will find the database associated with the target tenant corresponding to the user based on the tenant table and the data source table, and then switch the connection of the designated operating system from the first database to the database associated with the target tenant corresponding to the user.

[0076] The multi-tenant database isolation method provided by the embodiment of the present invention comprises: if a user's business request is received, the target tenant corresponding to the tenant is read from the tenant table of the preset multi-tenant management module; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is connected to a first database in communication; the multi-tenant management module is preset with a tenant table and a data source table; the tenant table is used to store the tenant information of the tenant, and the data source table is used to store the information of the data source of the tenant, and each data source corresponds to a database; the data source information corresponding to the target tenant is read from the data source table of the multi-tenant management module; the second database corresponding to the target tenant is determined by the read data source information; wherein the structure of the second database is consistent with that of the first database; and the specified operating system is switched from the first database to the second database. The method not only realizes the database isolation of the tenant, but also further improves the convenience of data query by presetting the tenant table and the data source table in the multi-tenant management module, and each data source corresponds to a tenant's database. In addition, the method also sets a metadata table in the multi-tenant management module, where the metadata table is used to store metadata information of the business table in the database, generates an initialization script for the target tenant's business database based on the metadata information, and initializes the business table in the business database corresponding to the target tenant through the initialization script, thereby facilitating the maintenance of data information of databases of different tenants and further improving the convenience of data maintenance.

[0077] Example 3

[0078] The embodiment of the present invention also provides a multi-tenant database isolation device, such as Figure 4 As shown, Figure 4 A schematic diagram of a multi-tenant database isolation device provided by an embodiment of the present invention includes:

[0079] The target tenant determination module 41 is used to determine the target tenant corresponding to the tenant according to the preset multi-tenant management module if a business request from the user is received; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is communicated with the first database; the multi-tenant management module is used to manage the logical relationship between multiple databases, and each database corresponds to a tenant.

[0080] The second database determination module 42 is used to determine the second database corresponding to the target tenant according to the multi-tenant management module; wherein the structure of the second database is consistent with that of the first database.

[0081] The database switching module 43 is used to switch the connection of the designated operating system from the first database to the second database.

[0082] The target tenant determination module 41, the second database determination module 42 and the database switching module 43 are connected in sequence.

[0083] In one possible implementation, the multi-tenant management module is preset with a tenant table and a data source table; the tenant table is used to store tenant information of the tenant, and the data source table is used to store information of the data source of the tenant, and each data source corresponds to a database. The target tenant determination module 41 is also used to read the target tenant corresponding to the tenant from the tenant table of the multi-tenant management module if a business request from the user is received.

[0084] In another possible implementation, the multi-tenant management module is preset with a tenant table and a data source table; the tenant table is used to store tenant information of the tenant, and the data source table is used to store information of the data source of the tenant, and each data source information corresponds to a database. The second database determination module 42 is also used to read the data source information corresponding to the target tenant from the data source table of the multi-tenant management module; and determine the second database corresponding to the target tenant by reading the data source information.

[0085] In another possible implementation, the second database determination module 42 is also used to receive a database creation request of the target tenant; the database creation request carries basic information of the target tenant; the basic information of the target tenant is saved in a preset tenant table of the multi-tenant management module; a data source configuration file is created based on the basic information of the target tenant, and the data source of the target tenant is registered; the information of the registered data source is saved in the preset data source table of the multi-tenant management module; a business database of the target tenant is created according to a preset database table creation statement configuration; wherein the business database includes at least one business table; initialization operations are performed on the business tables in the business database through a preset initialization script to obtain a created second database; wherein the initialization script is obtained based on the first database.

[0086] In another possible implementation, the second database determination module 42 is further configured to obtain metadata of the business table in the first database; parse the metadata to obtain corresponding metadata information; and generate an initialization script for the business database according to the metadata information.

[0087] In another possible implementation, the second database determination module 42 is further configured to extract metadata of the business table in the first database through a pre-installed Metacat.

[0088] In another possible implementation, the second database determination module 42 is further used to save the configuration information of the second database into the database table of the multi-tenant management module; wherein the configuration information includes: storage path, backup strategy, and access strategy of the database file.

[0089] In another possible implementation, the second database determination module 42 is further configured to save the metadata information into a preset metadata table of the multi-tenant management module.

[0090] The multi-tenant database isolation device provided in the embodiment of the present invention has the same technical features as the multi-tenant database isolation method provided in the above embodiment, so it can also solve the same technical problems and achieve the same technical effects.

[0091] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0092] Example 4

[0093] This embodiment provides an electronic device, including a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the steps of a multi-tenant database isolation method.

[0094] See also Figure 5 A structural schematic diagram of an electronic device is shown, which includes: a memory 51 and a processor 52. The memory 51 stores a computer program that can be run on the processor 52. When the processor executes the computer program, the steps provided by the above-mentioned multi-tenant database isolation method are implemented.

[0095] like Figure 5 As shown, the device further includes: a bus 53 and a communication interface 54, a processor 52, a communication interface 54 and a memory 51 are connected via the bus 53; the processor 52 is used to execute executable modules stored in the memory 51, such as computer programs.

[0096] The memory 51 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 54 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.

[0097] The bus 53 may be an ISA bus, a PCI bus, or an EISA bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0098] Among them, the memory 51 is used to store the program, and the processor 52 executes the program after receiving the execution instruction. The method executed by the multi-tenant database isolation method device disclosed in any embodiment of the present invention can be applied to the processor 52, or implemented by the processor 52. The processor 52 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 52. The above processor 52 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 51, and the processor 52 reads the information in the memory 51 and completes the steps of the above method in combination with its hardware.

[0099] Furthermore, an embodiment of the present invention also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by the processor 52, the machine-executable instructions prompt the processor 52 to implement the above-mentioned multi-tenant database isolation method.

[0100] The multi-tenant database isolation method, device and electronic device provided in the embodiments of the present invention have the same technical features, so they can also solve the same technical problems and achieve the same technical effects.

[0101] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0102] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0103] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, it should be understood by those skilled in the art that any person familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or perform equivalent replacements on some of the technical features thereof; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A multi-tenant database isolation method, characterized in that: include: If a service request from a user is received, a target tenant corresponding to the user is read from a tenant table of a multi-tenant management module; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is in communication connection with a first database; the multi-tenant management module is used to manage the logical relationship between multiple databases, and each database corresponds to a tenant; a tenant table and a data source table are preset in the multi-tenant management module; the tenant table is used to store tenant information of the tenant, and the data source table is used to store information of the data source of the tenant, and each data source corresponds to a database; Reading information of the data source corresponding to the target tenant from the data source table of the multi-tenant management module; The second database corresponding to the target tenant is determined by reading the information of the data source; wherein the structure of the second database is consistent with that of the first database; and the second database is pre-created in the following manner: receiving a database creation request from the target tenant; the database creation request carries basic information of the target tenant; Saving the basic information of the target tenant in a preset tenant table of the multi-tenant management module; Create a data source configuration file according to the basic information of the target tenant, and register the data source of the target tenant; Saving the information of the registered data source into the preset data source table of the multi-tenant management module; According to the preset database table creation statement configuration, create the business database of the target tenant; wherein the business database includes at least one business table; The business table in the business database is initialized by a preset initialization script to obtain a created second database; wherein the initialization script is obtained by: Obtaining metadata of the business table in the first database; Parsing the metadata to obtain corresponding metadata information; Generate an initialization script for the business database according to the metadata information; The designated operating system is switched from the first database to the second database.

2. The method according to claim 1, characterized in that The step of obtaining metadata of the business table in the first database includes: The metadata of the business table in the first database is extracted by using the pre-installed Metacat.

3. The method according to claim 1, characterized in that After the step of initializing the business table in the business database by using a preset initialization script to obtain a created second database, the method further includes: The configuration information of the second database is saved in the database table of the multi-tenant management module; wherein the configuration information includes: a storage path, a backup strategy, and an access strategy of the database file.

4. The method according to claim 1, characterized in that: After the step of parsing the metadata to obtain corresponding metadata information, the method further includes: The metadata information is saved in a preset metadata table of the multi-tenant management module.

5. A multi-tenant database isolation device, characterized in that: include: A target tenant determination module is used to read the target tenant corresponding to the user from the tenant table of the multi-tenant management module if a service request from the user is received; wherein the multi-tenant management module runs on a specified operating system, and the specified operating system is connected to the first database in communication; the multi-tenant management module is used to manage the logical relationship between multiple databases, and each database corresponds to a tenant; the multi-tenant management module is preset with a tenant table and a data source table; the tenant table is used to store tenant information of the tenant, and the data source table is used to store information of the data source of the tenant, and each data source corresponds to a database; a second database determination module, configured to read the information of the data source corresponding to the target tenant from the data source table of the multi-tenant management module; determine the second database corresponding to the target tenant by the read information of the data source; wherein the structure of the second database is consistent with that of the first database; the second database is preliminarily created by: receiving a database creation request of the target tenant; the database creation request carries the basic information of the target tenant; saving the basic information of the target tenant into the preset tenant table of the multi-tenant management module; creating a data source configuration file according to the basic information of the target tenant, and registering the data source of the target tenant; saving the information of the registered data source into the preset data source table of the multi-tenant management module; creating a business database of the target tenant according to the preset database table creation statement configuration; wherein the business database includes at least one business table; initializing the business table in the business database by a preset initialization script to obtain the created second database; wherein the initialization script is obtained by: obtaining the metadata of the business table in the first database; parsing the metadata to obtain the corresponding metadata information; generating the initialization script of the business database according to the metadata information; A database switching module is used to switch the connection of the designated operating system from the first database to the second database.

6. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the multi-tenant database isolation method described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Data table generation method and equipment

    CN106528070A

  • Multi-tenant database isolation method and system, electronic equipment and computer storage medium

    CN110765489A