Specific embodiment
To keep the purposes, technical schemes and advantages of the embodiment of the present application clearer, below in conjunction with the embodiment of the present application
In attached drawing, the technical scheme in the embodiment of the application is clearly and completely described, it is clear that described embodiment is
Some embodiments of the present application, instead of all the embodiments.Based on the embodiment in the application, those of ordinary skill in the art
Every other embodiment obtained without making creative work, shall fall in the protection scope of this application.
To be further explained below in conjunction with attached drawing with specific embodiment convenient for the understanding to the embodiment of the present application
Bright, embodiment does not constitute the restriction to the embodiment of the present application.
Database switching method provided by the embodiments of the present application and device, suitable for the scene switched over to database,
The business datum amount for being particularly suitable for application server processes is doubled and redoubled within the short time (e.g., one day), is restored to again later
Business datum amount before growth, thus the scene that the data capacity for needing application server to connect is adjusted repeatedly.
Fig. 1 is a kind of database switching method flow chart that embodiment provides of the application.The executing subject of the method can
Think the equipment with processing capacity: server or system or device, as shown in Figure 1, the method specifically includes:
Step 110, it is pre-configured with the first data source for connecting first database in the flrst mode, and is configured in the second mould
The second data source of the first database and the second database is connected under formula simultaneously.
Illustrate herein, mode is divided according to the quantity of server connection data storehouse.Such as, when server only connects N
When a database, wherein N is natural number, then can be as the first mode of server;And when server needs to connect n*
It, then can be as the second mode of server when N number of database.In e-commerce website, first mode can be day
Norm formula, i.e., the several databases for only needing server to be connected and fixed, so that it may normally handle all business datums;And second
Mode can (e.g., double 11) server needs to connect the database under daily mode at double, just can normally locate for big rush mode
Manage all business datums.Above-mentioned first database can be used under the daily mode of server to the first industry to be multiple
The storage for data of being engaged in;In addition, being also used to the storage under the big rush mode of server to the second business datum.Due in server
Big rush mode under, only connect a first database server cannot handle the second all business datums, therefore, it is also desirable to connect
Second database;Second database can be multiple, can hardware device identical with other Database vendors, so as to
Achieve the purpose that save the cost.
The first business datum or the second business datum in the present invention is as follows from the process for being created to transmission: business is flat
Platform -> intercourse platform -> channel gateway -> user, i.e. business platform first generate business datum, later send out the business datum of generation
Intercourse platform is given, received business datum is stored by the server on backstage by intercourse platform, later by above-mentioned industry
Business data by channel (e.g., short message, mail, Wang Wang, client push, stand in believe etc.) gateway is sent to user.
It should be noted that above-mentioned first business datum or the second business datum refer to from the Life Cycle for being created to transmission
Phase relatively short data, e.g., the short message check code etc. that business platform generates, what these data generally were intended to send in time;Though
Some right data may configure delay time, but delay time generally will not be too long, generally can be within 7 days.
Data source, that is, data source is to provide the device or original media of certain required data.It is deposited in data source
All information for establishing database connection are stored up.By providing correct data source name, so that it may find corresponding database
Connection, i.e., according to data source, so that it may establish the connection of database corresponding with data source.In general, pass through one
The example of data source can be connect with a Database, e.g., be passed through data source name (Data Source Name, DSN)
It can be connect with a unique Database.
In step 110, being pre-configured with and connecting the first data source of first database in the flrst mode is in server
The first data source of connection first database is write in the code of upper publication in advance, but according to the first data source, establish and
The connection of first database namely server can't in first database storage service data.Similarly, it can be only fitted to
The second data source of the first database and the second database is connected under two modes simultaneously.Herein, the second data source can be with
Including two data sources, that is, connect the data source of first database, and the data source of the second database of connection.
It is understood that can then be pre-configured with multiple connection first databases when first database is multiple
First data source;When the second database is multiple, it is pre-configured with the second data source of the second database of multiple connections, wherein
Each second data source includes two data sources.
Step 120, according to first data source, the connection with the first database is established.
I.e. in the flrst mode, server connection is first database.Such as, 10 first are pre-configured in step 110
Data source then can establish the company of 10 first databases corresponding with 10 the first data sources according to 10 the first data sources
It connects.Server and 10 first databases are established after connection, it can the storage service data in first database.
Step 130, when receiving the instruction for switching to the second mode from the first mode, according to described second
Data source, by the connection with the first database switch to simultaneously with the first database and second database
Connection.
It herein, can be a character string from the instruction that the first mode switches to the second mode.Since this refers to
Order is sent in the case that the code issued on the server has been run, therefore, pre- when wanting to change dynamically at runtime
The mode (configuration parameter) first configured, it is necessary to character string (resource value) is updated into the memory of respective server immediately, so as to
It comes into force.In one implementation, change the resource value in server memory by configuration center dynamic, immediately, this
Place, configuration center can be for can receive character string, and character string is pushed to the software program or system of server.
Database switching method schematic diagram shown in Figure 2, in Fig. 2, App cluster includes multiple servers, upper part
Affix one's name to multiple application programs, wherein multiple common one service message of collaborative process of application program;In the flrst mode, App cluster
Only connection is established with 10 first databases (database i.e. before dilatation);And when business datum amount is doubled and redoubled, 10
The capacity of one database may not enough store the business datum after increasing, and therefore, it is necessary to the capacity to database to expand, i.e.,
The instruction that the second mode is switched to the pocket transmission of App collection from the first mode, when App cluster is received from described first
Pattern switching to the second mode instruction when, App cluster simultaneously with 10 first databases and 40 under first mode
A second database (database i.e. after dilatation) establishes connection, wherein due in the flrst mode, counting with 10 first
Connection is established according to library, therefore it may only be necessary to according to 40 the second data sources, establishes 40 corresponding with 40 the second data sources the
The connection of two databases;And 40 the second databases can be with the Database vendors hardware device under other modes, i.e., 40
Physical host where two databases can also establish the database under other modes, so as to reach the mesh of shared resource
's.Further, since under the second mode, while 10 first databases being connected under first mode, it is possible thereby to save into
This.
Optionally, it is received before the instruction that the first mode switches to the second mode described, the side
Method further include:
The first business datum is received, the identification information of the first business datum recipient is carried in first business datum;
According to the identification information of the first business datum recipient, first business datum is stored to described first
In database.
Herein, the first business datum refers to the business datum received in the flrst mode;First business datum recipient
Identification information be the numeric string that can uniquely identify a recipient.
In Fig. 2, in the flrst mode, it is assumed that the first business number carried in the first business datum that App cluster receives
According to the identification information of recipient are as follows: 110010.In one implementation, believed according to the mark of the first business datum recipient
Breath carries out horizontal division to above-mentioned the first business datum received, specifically: 110010%10=0, also i.e. by above-mentioned first
Business datum is stored into the 1st first database (i.e. #0 database).
Optionally, it is described by with the connection of the first database switch to simultaneously with the first database and described
After the connection of second database, the method also includes:
The second business datum is received, the identification information of the second business datum recipient is carried in second business datum;
According to the identification information of the second business datum recipient, second business datum is stored to described first
In database or second database.
Herein, the second business datum is the business datum received under the second mode;Second business datum recipient's
Identification information is the numeric string that can uniquely identify a recipient.
In Fig. 2, when being switched to second mode, it is assumed that second carried in the second business datum that App cluster receives
The identification information of business datum recipient are as follows: 500051.In one implementation, according to the mark of the second business datum recipient
Know information, horizontal division carried out to above-mentioned the second business datum received, specifically: 500051%50=1, it also i.e. will be above-mentioned
Second business datum is stored into the 2nd first database (i.e. #1 database);And it is carried in the second business datum when receiving
The second business datum recipient identification information are as follows: when 500040, due to 500040%50=40, also i.e. by above-mentioned second industry
Business data are stored into the 41st the second database (i.e. #40 database).
Optionally, it is described by with the connection of the first database switch to simultaneously with the first database and institute
After the connection for stating the second database, the method also includes:
When receiving the instruction for switching to the first mode from the second mode, by while with first data
The connection of library and second database switches to the connection with the first database.
In Fig. 2, the case where business datum amount is doubled and redoubled is usually that anticipated that, and its duration is of short duration
's.After the business datum amount after being doubled and redoubled continues the preset time, then the data volume that can be restored to before increasing, and in industry
It, can great wave if continuing to connect with first database and the second Database simultaneously after data volume of being engaged in is restored
Take resource, therefore, it is necessary to the instruction of first mode is switched to the pocket transmission of App collection from second mode.App cluster is on receiving
After stating instruction, the connection simultaneously with 10 first databases and 40 the second Databases under first mode is switched
To the connection only established with 10 first databases.As a result, App cluster can according to instruction, can conveniently realize from expansion
The connection of database after appearance switches to the connection with the database before dilatation.
It should be noted that switch back into after first mode, when App cluster receives other business datums, then basis
The identification information of other business datum recipients stores other business datums into 10 first databases.
Optionally, the method also includes:
According to the first migration instruction received, the first business datum in the first database is migrated to backup number
According in library;Alternatively,
According to the second migration instruction received, by the second industry in the first database or second database
Data Migration be engaged in into backup database.
Herein, backup database be served only for in first database the first business datum or first database or
The second business datum in second service database is backed up, and does not support additions and deletions change the functions such as to look into.In addition, the first migration instruction
It is received in the case where end to can be the life cycle of the first business datum in first database;Second migration instruction can
To be that the life cycle of two business datums in first database and the second database is received in the case where end.
In Fig. 2, according to the instruction for switching to from the first mode second mode, App cluster will from 10
The connection of first database switches to while the company with 10 first databases and 40 the second databases under first mode
After connecing, App cluster receives the first migration instruction, and is instructed according to the first migration, by the first business in 10 first databases
Data Migration is into backup database;In addition, according to the instruction for switching to the first mode from the second mode, App
Cluster will switch to and 10 from the connection simultaneously with 10 first databases and 40 the second databases under first mode
After the connection of first database, App cluster receives the second migration instruction, and is instructed according to the second migration, by 10 the first data
The second business datum in library or 40 the second databases is migrated into backup database.The first business in backup database
Data or the second business datum can be used for user's subsequent query.
Database switching method provided by the embodiments of the present application is pre-configured with and connects first database in the flrst mode
First data source, and configure the second data for connecting the first database and the second database simultaneously under the second mode
Source;According to first data source, the connection with the first database is established;It is switched to when receiving from the first mode
When the instruction of the second mode, according to second data source, by with the connection of the first database switch to simultaneously with
The connection of the first database and second database.Thus, it is possible to realize easily before dilatation and after dilatation
It is switched between database, so as to greatly save time cost, saves computer resource further, it is also possible to reach
Purpose.
Accordingly with above-mentioned database switching method, a kind of database switching device that the embodiment of the present application also provides, such as
Shown in Fig. 3, which includes: configuration unit 301, establishes connection unit 302 and switch unit 303;
Configuration unit 301 for being pre-configured with the first data source for connecting first database in the flrst mode, and configures
Connect the second data source of the first database and the second database simultaneously under the second mode;
Connection unit 302 is established, first data source for configuring according to configuration unit 301 is established and described the
The connection of one database;
Switch unit 303, for when receiving the instruction for switching to the second mode from the first mode, according to
Second data source, by with the connection of the first database switch to simultaneously with the first database and described second
The connection of database.
Optionally, described device further include: the first receiving unit 304 and the first storage unit 305;
First receiving unit 304 carries the first business number in first business datum for receiving the first business datum
According to the identification information of recipient;
First storage unit 305, for the identification information according to the first business datum recipient, by first industry
Business data are stored into the first database.
Optionally, described device further include: the second receiving unit 306 and the second storage unit 307;
Second receiving unit 306 carries the second business number in second business datum for receiving the second business datum
According to the identification information of recipient;
Second storage unit 307, for the identification information according to the second business datum recipient, by second industry
Business data are stored into the first database or second database.
Optionally, switch unit 302 are also used to that the finger for switching to the first mode from the second mode ought be received
When enabling, the connection simultaneously with the first database and second database is switched into the company with the first database
It connects.
Optionally, described device further include: migration units 308 will be described for being instructed according to the first migration received
The first business datum in first database is migrated into backup database;Alternatively,
According to the second migration instruction received, by the second industry in the first database or second database
Data Migration be engaged in into backup database.
The database switching device that the application another kind embodiment provides implants the number that a kind of embodiment of the application provides
According to library switching method, therefore, the specific work process of device provided by the present application does not repeat again herein.
Database switching device provided by the present application, configuration unit 301 are pre-configured with the first number of connection in the flrst mode
According to first data source in library, and configures and connect the second of the first database and the second database simultaneously under the second mode
Data source;Connection unit 302 is established according to first data source, establishes the connection with the first database;Switch unit
303 when receiving the instruction for switching to the second mode from the first mode, will be with institute according to second data source
The connection for stating first database switches to while the connection with the first database and second database.As a result, may be used
It is easily being switched between the database after dilatation before dilatation with realizing, so as to greatly save time cost,
Further, it is also possible to achieve the purpose that save computer resource.
Professional should further appreciate that, described in conjunction with the examples disclosed in the embodiments of the present disclosure
Object and algorithm steps, can be realized with electronic hardware, computer software, or a combination of 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 implemented in hardware or software actually, the specific application and design constraint depending on technical solution.
Professional technician can use different methods to achieve the described function each specific application, but this realization
It is not considered that exceeding scope of the present application.
The step of method described in conjunction with the examples disclosed in this document or algorithm, can be executed with hardware, processor
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 has carried out further the purpose of the application, technical scheme and beneficial effects
It is described in detail, it should be understood that being not used to limit the application the foregoing is merely the specific embodiment of the application
Protection scope, within the spirit and principles of this application, any modification, equivalent substitution, improvement and etc. done should all include
Within the scope of protection of this application.