Background technology
The fast development of Internet technology causes traditional database to face huge challenge when tackling mass data, distributed
Key-value Key-Value databases come into being, and Key-Value databases include the non-relational distributed data base increased income
HBase, non-relational database Cassandra, the no SQL of the database of non-relational etc..The distribution of Key-Value databases
Framework, mass data can be stored by having with respect to traditional Relational DataBase, and a table can have more than one hundred million rows;It is stored towards row, face
The storage of nematic (race) and permission control, arrange (race) independent retrieval;Sparse storage for empty row, is not take up memory space, can
It is very sparse table to be designed.
Multi-tenant technology is mainly used for multiple tenants and shares hardware resource, multiple public Application Instances of tenant.
In the prior art, multi-tenant technology mainly includes following three kinds of schemes in terms of data storage:
1. each tenant possesses self contained data base
Mutually independent database is provided for different tenants, such data isolation is best, and due to that can be different
The individually designed database structure of user helps to simplify the design of database structure, breaks down and recover also relatively easy.But
Self contained data base is established for each tenant, for different tenants without really sharing hardware resource, acquisition cost and maintenance cost are high,
General operator can not receive.
2. tenant's shared data bank, but possess independent storehouse table
All tenants share a database, but different tenants possess independent storehouse table.Provide certain data it
Between isolation, but extend relatively cumbersome, be not easy to extend, cost is also higher, across tenant data statistics hardly possible.
3. tenant's shared data bank, shared data bank table
All tenant's shared data banks, shared library table, this method cost is minimum, sharing degree highest, allows the rent supported
Family is also most, but since the business demand between different tenants differs, needs well-designed data for such case
Storehouse.During using traditional Relational DataBase, when tenant need add custom field when, it is necessary in the database addition row, it is right
For Mr. Yu tenant, the row of other tenants addition are useless row to the tenant, but need to exist in the database, but when rent
, it is necessary to increase a large amount of row in the database, this results in extremely wasting there are substantial amounts of null value in database when amount amount is larger
Space.
The content of the invention
An embodiment of the present invention provides a kind of multi-tenant extended methods based on key-value database, effectively reduce multi-tenant
The operation cost and maintenance cost of database increase the autgmentability of multi-tenant database, reduce customization cost and the shortening of tenant
Customize the cycle.
An embodiment of the present invention provides a kind of multi-tenant extended method based on key-value database, the described method includes:
Obtain initial service entity metadata;
Customization stage, attribute of activating business on the initial service entity metadata define industry to the service attribute
Entity and display label, generation meet the specific transactions entity metadata of multi-tenant demand;
The example stage is generated, according to the specific transactions entity metadata, creates key-value Key-Value databases;
The example operation phase is inserted into the Business Entity of Key-Value databases using tenant identification as RowKey prefixes
Data, by the tenant identification generate RowKey query context inquiry business solid data, in the query context from
Business Entity data are taken out in the Key-Value databases, interactive interface is generated according to the specific transactions entity metadata,
So as to by the Business Entity data display.
Preferably, the initial service entity metadata and the specific transactions entity metadata include at least:Business
The table name of entity, the display label of Business Entity, the attribute column name of Business Entity, the data type of Business Entity, Business Entity
Index column mark and Business Entity attribute display label.
Preferably, in the generation example stage, the method further includes:
All tenants share a Key-Value database, and the initial service entity metadata is corresponding to be classified as
All tenants share.
Preferably, in the generation example stage, the method further includes:
It is described to activate business attribute for meeting the different business demand of the tenant, and at the same time generation and newly-increased industry
The corresponding extension columns of business attribute, the extension columns are only visible to the tenant.
Preferably, the Business Entity number that Key-Value databases are inserted into using tenant identification as RowKey prefixes
According to specifically further including:Using the tenant mark+Business Entity table name as the Business Entity data
RowKey prefixes.
Preferably, the query context inquiry business solid data that RowKey is generated by the tenant identification specifically wraps
It includes:The Key-Value databases are inquired about, according to the mark of the tenant and the table name setting inquiry model of the Business Entity
It encloses, in the query context of the setting, inquiry is carried out according to querying condition set by user and obtains the Business Entity data.
Preferably, it is described to be specifically included according to specific transactions entity metadata generation interactive interface:
The specific transactions entity metadata of the tenant is obtained according to the mark of the tenant;
According to the index column information of the specific transactions entity metadata of the tenant and data type generation query term;
Display label and Business Entity data display inquiry knot in the specific transactions entity metadata of the tenant
Fruit;
It is shown according to the display label of Business Entity of the specific transactions entity metadata of the tenant, the attribute of Business Entity
The New any of the newly-built page of the data type of indicating label and Business Entity generation.
Multi-tenant extended method proposed by the present invention based on key-value database, can generate positive advantageous effect, tool
Body is as follows:It supports the application for meeting tenant's individual demand by customizing generation, can be kept away for the similar business of operation flow
Exempt from overlapping development;Using shared Key-Value databases realization is facilitated to extend, cut operating costs, with newly-increased tenant's
Increase, with the growth of the userbase of tenant, the present invention is using tenant identification as the RowKey of all Business Entity data
Prefix facilitates realization to extend, cuts operating costs.
Embodiment one
The extension of the multi-tenant based on key-value database that embodiment one that the present invention will be described in detail by taking Fig. 1 as an example below provides
Method, Fig. 1 are the multi-tenant extended method flow chart provided in an embodiment of the present invention based on key-value database, of the invention real
It can be operation supporting platform to apply subject of implementation in example.Fig. 2 show that the embodiment of the present invention proposes based on key-value database
The functional block diagram of multi-tenant extended method.As shown in Fig. 2, the multi-tenant extension side proposed by the present invention based on key-value database
In method, using the operation supporting platform of expansible definable multi-tenant, which uses distribution Key-Value data stocks
Store up business information.With reference to shown in Fig. 1 and Fig. 2, this method comprises the following steps:
Step 101 obtains initial service entity metadata;
Initial service entity metadata includes at least:The table name of Business Entity, the display label of Business Entity, Business Entity
Attribute column name, the data type of Business Entity, the index column of Business Entity mark and Business Entity attribute display label.
Step 102, customization stage, attribute of activating business on the initial service entity metadata, to the business category
Property define Business Entity and display label, generation meets the specific transactions entity metadata of multi-tenant demand.
The initial service entity metadata and the specific transactions entity metadata include at least:The table of Business Entity
Name, the attribute column name of the display label of Business Entity, Business Entity, the data type of Business Entity, the index column of Business Entity
The attribute display label of mark and Business Entity.
Specifically, before operation supporting platform deployment, each module initial service entity member is formulated according to each modular service demand
Data, and Key-Value data Kuku table is created according to initial service metadata, for example, wherein service metadata structure is main
As shown in table 1:
1 service metadata structure table of table
It is as shown in table 2 according to template establishment database table CRM structures:
2 database table CRM structure tables of table
Step 103, generation example stage according to the specific transactions entity metadata, create key-value Key-Value numbers
According to storehouse.
In the generation example stage, the method further includes:
All tenants share a Key-Value database, and the initial service entity metadata is corresponding to be classified as
All tenants share.
Specifically, in the customization stage, tenant is on the basis of initial service entity metadata, according to domain knowledge to the first beginning of the school year
Pragmatic voxel data is customized, and by changing initial column information, increases self-defined column information generation tenant's specific transactions entity
Metadata.
Tenant 1 is certain educational institution, and according to business demand, the corresponding entity names of CRM are changed to " student ";Initial service
The corresponding attribute tags of " USER_NAME " row are changed to " student name " in entity metadata, and " USER_ID " corresponds to attribute tags
It is changed to " student number ";Increase attribute " grade " for Business Entity " student ", and define corresponding self-defined row, by customizing above, rent
It is as shown in table 3 that family 1 generates self-defined Business Entity metadata:
The self-defined Business Entity metadata of 3 tenant 1 of table generation
Tenant 2 is certain corporate user, and according to business demand, the corresponding entity names of CRM are changed to " employee ";Initial service
The corresponding attribute tags of " USER_NAME " row are changed to " employee name " in entity metadata, and " USER_ID " corresponds to attribute tags
It is changed to " employee number ";Increase attribute " department " for Business Entity " employee ", and define corresponding self-defined row, by customizing above,
It is as shown in table 4 that tenant 2 generates self-defined Business Entity metadata:
The self-defined Business Entity metadata of 4 tenant 2 of table generation
According to the self-defined Business Entity metadata that tenant 1 and tenant 2 generate, we can define several it is similar from
Business Entity metadata is defined, equally we assume that tenant N is certain enterprise management level personnel, according to business demand, CRM is corresponded to
Entity name be changed to " handle ";The corresponding attribute tags of " USER_NAME " row are changed to " pipe in initial service entity metadata
Reason person ", " USER_ID " corresponding attribute tags are changed to " administrator number ";Increase attribute " department " for Business Entity " employee ", and it is fixed
The corresponding self-defined row of justice, by customizing above, it is as shown in table 5 that tenant N generates self-defined Business Entity metadata:
The self-defined Business Entity metadata of 5 tenant N of table generations
In the generation example stage, the method further includes:
It is described to activate business attribute for meeting the different business demand of the tenant, and at the same time generation and newly-increased industry
The corresponding extension columns of business attribute, the extension columns are only visible to the tenant.
Different tenants share same database table using generation example after the extension of identical initial service entity metadata, initially
Business Entity metadata is corresponding to be classified as all tenants and shares;Meanwhile according to tenant generate specific transactions entity it is self-defined
Attribute adds self-defined extension columns for tenant, and self-defined extension columns are only from the tenant.After certain tenant adds self-defined row, only
There is the tenant in the row interpolation data, due to the sparse row storage characteristics of Key-Value databases, simultaneously there is no should by other tenants
The data of the self-defined row of tenant, are also not take up any redundant space.1 Business Entity of tenant " student " at this time, 2 Business Entity of tenant
The shared Key-Value database table CRM structures of " employee " and tenant N Business Entities " administrator " are extended to table 6 automatically:
Table 6Key-Value database table CRM structure extension tables
Step 104, example operation phase are inserted into Key-Value databases using tenant identification as RowKey prefixes
Business Entity data generate the query context inquiry business solid data of RowKey by the tenant identification, in the inquiry
In the range of from the Key-Value databases take out Business Entity data, according to the specific transactions entity metadata generate
Interactive interface, so as to by the Business Entity data display.
The query context inquiry business solid data that RowKey is generated by the tenant identification specifically includes:Inquiry
The Key-Value databases set query context, described according to the table name of the mark of the tenant and the Business Entity
In the query context of setting, inquiry is carried out according to querying condition set by user and obtains the Business Entity data.
In the example operation phase, Key- is inserted into using tenant identification as the RowKey prefixes of all Business Entity data
Value databases generate RowKey query contexts by the tenant identification and take out Business Entity number from Key-Value databases
According to according to the specific transactions entity metadata generation interactive interface after customization.
It is described to be specifically included according to specific transactions entity metadata generation interactive interface:
The specific transactions entity metadata of the tenant is obtained according to the mark of the tenant;
According to the index column information of the specific transactions entity metadata of the tenant and data type generation query term;
Display label and Business Entity data display inquiry knot in the specific transactions entity metadata of the tenant
Fruit;
It is shown according to the display label of Business Entity of the specific transactions entity metadata of the tenant, the attribute of Business Entity
The New any of the newly-built page of the data type of indicating label and Business Entity generation.
The Business Entity data that Key-Value databases are inserted into using tenant identification as RowKey prefixes are specifically gone back
Including:Using RowKey prefix of the table name as the Business Entity data of mark+Business Entity of the tenant.
Business Entity " student " metadata is obtained by tenant identification " Tenant001 ", it is real by the business of the metadata
Body attribute display label and data type generation create or the content and its pattern of the modification page.Whole user information is filled in, number
According to insertion Key-Value databases.When being inserted into data, using " tenant identification+storehouse table name " as data RowKey's
Prefix, such as " Tenant001CRMStudent001 ".Similarly, represent that " Tenant002 " obtains Business Entity " member by tenant 2
Work " generates the newly-built or modification page afterwards, while is inserted into employee " Tenant002CRMEmployee001 ", and tenant N is similarly such as
This.Data at this time in the table of CRM storehouses are as shown in table 7, and wherein BASE represents initial service metadata structure table, and CUSTOM, which is represented, to be expanded
Exhibition industry business metadata structure table:
Table 7CRM storehouses table data
RowKey |
Row |
Tenant001CRMStudent001 |
BASE:USER_ID:Student001 |
Tenant001CRMStudent001 |
BASE:USER_NAME:King is small by two |
Tenant001CRMStudent001 |
BASE:USER_EMAIL:wangxe@stu.com |
Tenant001CRMStudent001 |
CUSTOM:STUDENT_LEVEL:1 |
Tenant002CRMEmployee001 |
BASE:USER_ID:Employee001 |
Tenant002CRMEmployee001 |
BASE:USER_NAME:Li Du |
Tenant002CRMEmployee001 |
BASE:USER_EMAIL:lid@company.com |
Tenant002CRMEmployee001 |
CUSTOM:DEPARTMENT:Research and development |
During into query page, identify " Tenant001 " using tenant 1 and obtain Business Entity " student " metadata, in member
All index entry generation query pages are obtained in data, index entry display label includes " student name ", " mailbox ", " grade ".
Query result shows self-defined Business Entity all properties, including " student number ", " student name ", " mailbox ", " grade ".Similarly,
" Tenant002 " is identified using tenant 2 and obtains Business Entity " employee " metadata, obtains all index entry generations in the metadata
Query page, index entry display label include " employee name ", " mailbox ", " department ".Query result shows that self-defined business is real
Body all properties, including " employee number ", " employee name ", " mailbox ", " department ".When inquiring about certain tenant's Ku Biao data, according to
Tenant identification and storehouse table name setting query context, carry out inquiry according to querying condition set by user in the range and obtain number
According to, specifically, StartRow is set as using " tenant identification+storehouse table name ", StartRow plus one are set as EndRow,
All data of the tenant in the table of storehouse are i.e. within this range, so that the inquiry velocity of tenant is only and the tenant number of oneself
It is related according to measuring, and it is unrelated with other tenant data amounts.In this case, when inquiring about 1 Business Entity of tenant " student " data, setting
StartRow is " Tenant001CRM ", and EndRow is " Tenant 001CRN ", and after setting range, inquiry 1 data of tenant only need
Matching inquiry condition in the range, without scanning entire database table.
Specifically, in the example operation phase, when 1 business demand of tenant changes, " learned if desired for for Business Entity
It is raw " increase attribute " specialty ", then only it need to increase the information of the attribute and self-defined row name in database template, it need not
Do any additional customized exploitation or deployment.Need to be only distribution when operator tenant, which increases, causes server capacity inadequate
Key-Value databases increase server, need not do additional Data Migration.
In conclusion the present invention proposes a kind of multi-tenant extended method based on key-value database, this method is customizing
Stage activates business entity according to domain knowledge on the basis of initial metadata, and defines the display of Business Entity and its attribute
Label, generation meet the certain metadata of tenant's different business demand;In the generation example stage, the business extended according to user is real
Voxel data creates Key-Value databases for tenant;In the example operation phase, when tenant is to database Insert service data,
Business datum RowKey is generated for prefix with " tenant identification+storehouse table name ", by the specific transactions entity member number for obtaining tenant
According to generation interactive interface, query context is set from database taking-up business datum by RowKey and is shown.The present invention supports logical
It crosses customization generation and meets the application of tenant's individual demand, it can be to avoid overlapping development, together for the similar business of operation flow
The Key-Value databases that Shi Caiyong shares facilitate realization to extend, and cut operating costs.
Professional should further appreciate that, be described with reference to the embodiments described herein each exemplary
Unit and algorithm steps can be realized with the combination of electronic hardware, computer software or the two, hard in order to clearly demonstrate
The interchangeability of part and software generally describes each exemplary composition and step according to function in the above description.
These functions are performed actually with hardware or software mode, specific application and design constraint depending on technical solution.
Professional technician can realize described function to each specific application using distinct methods, but this realization
It is not considered that the scope beyond the embodiment of the present invention.
The step of method or algorithm for being described with reference to the embodiments described herein, can use hardware, processor to perform
The combination of software module or the two is implemented.Software module can be placed in random access memory (RAM), memory, read-only memory
(ROM), electrically programmable ROM, electrically erasable ROM, register, hard disk, moveable magnetic disc, CD-ROM or technical field
In any other form of storage medium well known to interior.
Above-described specific embodiment, to the embodiment of the present invention, technical solution and advantageous effect carried out into one
Step is described in detail, it should be understood that the foregoing is merely the specific embodiments of the embodiment of the present invention, is not used to limit
Determine the protection domain of the embodiment of the present invention, all any modifications within the spirit and principle of the embodiment of the present invention, made are equal
Replace, improve etc., it should be included within the protection domain of the embodiment of the present invention.