Embodiment
Here exemplary embodiment will be illustrated in detail, its example is illustrated in the accompanying drawings.Following description is related to
During accompanying drawing, unless otherwise indicated, the same numbers in different accompanying drawings represent same or analogous key element.Following exemplary embodiment
Described in embodiment do not represent all embodiments consistent with this specification.On the contrary, they are only and such as institute
The example of the consistent apparatus and method of some aspects be described in detail in attached claims, this specification.
It is only merely for the purpose of description specific embodiment in the term that this specification uses, and is not intended to be limiting this explanation
Book." one kind " of used singulative, " described " and "the" are also intended to bag in this specification and in the appended claims
Most forms are included, unless context clearly shows that other implications.It is also understood that term "and/or" used herein is
Refer to and any or all may be combined comprising the associated list items purpose of one or more.
It will be appreciated that though various information may be described using term first, second, third, etc. in this specification, but
These information should not necessarily be limited by these terms.These terms are only used for same type of information being distinguished from each other out.For example, do not taking off
In the case of this specification scope, the first information can also be referred to as the second information, and similarly, the second information can also be claimed
For the first information.Depending on linguistic context, word as used in this " if " can be construed to " ... when " or
" when ... " or " in response to determining ".
Referring to Fig. 1, shown in Fig. 1 being the system for realizing data processing shown in the exemplary embodiment of this specification one
100 Organization Chart.System 100 can include the operation for entering row data communication via network 112 and one or more clients 106
Server 105, and independently of Operation Server 105 or it is integrated in the database 115,116 of Operation Server 105.Network 112
Such as internet, in-house network, extranets, wide area network (WAN), LAN (LAN), wired network, wireless network or other can be included
Suitable network etc., or any combinations of two or more this kind of networks.Through the discussion of exemplary, Ying Liao
Solution, term " data " and " information " interchangeably can be used to refer to may be present in computer based environment in this manual
Text, image, audio, the information of video or any other form.
Commercially available HTTP (HTTP) server application can be included on Operation Server 105, such as
HTTP server, Internet Information Service (IIS) and/or other servers.
Client 106 can be provided with the network equipment of application.Referred to herein as application can be to provide various services
The application that is related to of operation system, such as financial system that account was transferred to or produced service is provided, the communication of Communications service is provided
System etc., network equipment from hardware can include desktop PC, laptop computer, tablet PC, smart phone,
Handheld computer, personal digital assistant (" PDA "), or the device of any other wired or wireless processor driving.
Once user initiates registration request, operation clothes using client 106 and by network 112 to Operation Server 105
Business device 105 can record the log-on message of the user, and preset authority is opened up in Operation Server 105 according to registration request
Account.Furthermore, it is possible to it is stored with the account of each user's registration, (login password and/or business processing are close for the various passwords of each account
Code etc.) and the authentication information that uploads during user's registration.
Follow-up user every time initiates the service request for some business by client 106, such as:Service data visitation
Request etc. is transferred in request, business datum, so as to which when accessing Operation Server 105, Operation Server 105 is based on each industry
The mark for showing user identity of the ID carried in business request etc, can know and record such service request.It is special
It is other, the request time of the user can be recorded, it is selectable, IP address when initiating request can also be recorded, or adopted
One in the type of hardware of network equipment, or the category information of operating system version that is based on of client release/client
It is individual or multiple.Particularly, the service request updated for data occur, such as it is transferred to or produces the service request of resource, modification
Request of service condition etc., Operation Server 105 can also record the service request, and corresponding internal or external by performing
Operation after give user and specifically respond.Usually, all service requests, can be left in Operation Server 105 corresponding
Record.Operation Server 105 can sort out all industry of different user respectively according to information such as ID, business description information
Business request., can also be according to above-mentioned ID for the interaction between the service request of interbehavior, such as different registered users
Classify and form set.
Operation Server 105 can store above-mentioned service request with database 115 or database 116, respond the business
Business datum caused by the operation of request and the operation, database 115 and database 116 can be used for customer in response end 106
The database of service request.
For the application scenarios of redundancy backup, database 115 can be the redundancy backup of primary database and the primary database
A database in database, database 116 can be one in the redundancy backup database of primary database and the primary database
Database.
For the application scenarios of Data Migration, database 115 can be the migrating data of primary database and the primary database
A database in storehouse, database 116 can be the databases in the migrating data storehouse of primary database and the primary database.Its
In, primary database or migrating data storehouse can be Qracle databases, OceanBase databases, MySQL database etc..
Except database 115 and the external system 100 of database 116 can also include other databases.Be stored in database 115 or
Data in database 116, it is associated with the operating procedure of various embodiments described below.
, may for the consideration of data safety, data-handling efficiency, database O&M cost etc. in practical application
There is the demand in switch data storehouse.By taking the system shown in Fig. 1 as an example, database 115 is the number that Operation Server 105 is read and write always
According to storehouse, source database can be referred to as, Operation Server 105, can preferential access originator after the service request of client 106 is received
Database.Because the attributes such as the data-handling efficiency of database 116, safety guarantee, O&M cost are better than database 115, therefore,
Need to replace database 115 with database 116, the database that Operation Server 105 preferentially accesses is switched to by database 115
Database 116, database 116 can be referred to as to the target database for being used for replacing source data.
In order to after target database replaces source database, still ensure that Operation Server 105 is that client 106 provides just
Normal service, it is necessary to which business datum is moved into target database by source database before switch data storehouse.Below in conjunction with attached
Figure, describe the database handoff procedure of this specification embodiment in detail.
Referring to Fig. 2, Fig. 2 is the flow chart of the database switching method shown in the exemplary embodiment of this specification one, should
Embodiment can apply on the Operation Server shown in Fig. 1, comprise the following steps S201-S203:
Step S201, it is data to be synchronized by the data markers write when there is data to write source database, wherein,
Source database is the database that operation system preferentially accesses.
If step S202, reaching predetermined lock in time, the number being labeled into target database synchronization source database
According to.
Step S203, after the data being labeled in source database are synchronized to target database, target database is switched
The database preferentially accessed for the operation system.
In the present embodiment, operation system can refer to service provider and provide the user each business involved during related service
Equipment, such as:Service request for customer in response end, the Operation Server to client offer respective service.
In practical application, Operation Server receives the service request of client transmission or detects user's (such as business
Keeper) directly in the service request triggered on Operation Server, source database can be performed corresponding with service request
Operation, referred to herein as operation can be read operation, write operation, lock operation etc., write operation can refer to again insertion operation, change
At least one of in operation, deletion action.And during business scenario difference, the service request that Operation Server receives is different, rings
When answering the service request to source database execution operation, operated data may also be different, such as:Business scenario is electronics
During the scene of commercial field, the service request of reception is asked for order processing, and operated data are order data;Business scenario
For financial field scene when, the service request of reception is inquiry into balance request, and operated data can be account balance number
According to.In other business scenarios, other kinds of service request, the other kinds of data of operation can also be received, this specification is real
It is without limitation to apply example.
Received or the service request that detects when Operation Server responds, when writing data to source database, it can be determined that with
Whether original SQL query condition is included as the unique index of data configuration to be operated corresponding to on-unit, if bag
Contain, write operation directly is performed to target database, if do not included, according to the anti-industry looked into from database of where querying conditions
Business table, judges the unique index for whether including the affiliated business of data to be operated in the traffic table, original if do not included
SQL forbids performing write operation to target database, if including according to the unique index to mesh without band querying condition
Mark database and perform write operation.
It can be data to be synchronized by the data markers write, when specifically marking, a synchrodata table can be established,
Addition can characterize the sync mark of write data in the synchrodata table, such as:The index for the data write is added to together
In step data table, or directly the information of the index for the data write and description write operation is added in synchrodata table;
Corresponding write-in data sync mark can also be added directly in the tables of data of storage write-in data during mark, the sync mark can
Using be this programme designer it is predetermined corresponding data can be represented as characters such as the letters of data to be synchronized, numerals.At other
In embodiment, other modes can also be taken to mark data to be synchronized, this explanation embodiment is without limitation.
When writing data, when different to the operation performed by source database, the data of mark may also be different, example
Such as:When performing deletion action to source database, the index of the data of deletion can be added to describing the information of deletion action
Synchrodata table, after can also performing deletion action, the index of one group of data of gained is added to synchrodata table;To source number
When performing insertion operation according to storehouse, the information of the index of the data of insertion and description insertion operation can be added to synchrodata
Table, after can also performing insertion operation, the index of one group of data of gained is added to synchrodata table.
After the good data that this is write of mark, if not reaching predetermined lock in time, as long as there is data to write source number
, can be to perform operation of the data markers that will be write as data to be synchronized again according to storehouse.Referred to herein as lock in time can be with
Made a reservation for by the designer of this programme according to the application scenarios of reality.In some examples, the daily fixation period can be predefined for,
Such as 3 points to 6 points of daily morning.In other examples, it is general less than predetermined that probability that source database operated can also be predefined for
The period of rate threshold value, the probability threshold value can be other numerical value after 5%.
, can be to target database synchronization quilt if reaching the lock in time after the good data that this is write of mark
The data of mark, when not having data to be synchronized in target database, data to be synchronized are directly write into target database, mesh
When mark data have had the historical data related to data to be synchronized, according to sync mark or data to be synchronized to correlation
Historical data is updated.
, can be preferentially same by the data of newest mark according to the mark time synchronously during labeled data in practical application
Target database is walked, often completes the synchronization of one group or a data, the group or the data can be updated to same step number
According to can be data to be synchronized by characterize data when specifically updating to distinguish synchronous data and not synchronous data
Mark is deleted, and can also increase the mark that characterize data is synchronized data.In addition it is also possible to the data being synchronized to from last time are opened
Begin, continue synchronous follow-up data.In other examples, can also synchronous labeled data in other sequences, this specification
Embodiment is without limitation.
While the data being synchronously labeled, it is the database that operation system preferentially accesses that can keep source database,
It is easy to, when there are data to need to write source database, while synchronous labeled, write data into source database, and mark and write
Data.After the lock in time, data syn-chronization can be temporarily terminated, after next time reaches predetermined lock in time, followed by
It is continuous to carry out data syn-chronization.
Under some scenes, when first group of data is not write from source database, beginning label data to be synchronized, so
Mark and write before data to be synchronized in the data of source database, there may be at least part data to also need to be synchronized to number of targets
According in storehouse, so, can also be same to target database after the data being labeled in source database are synchronized to target database
Walk the data to be synchronized not being labeled in source database;Labeled data to be synchronized are not synchronized to target in source database
After database, then target database switched into the database that operation system preferentially accesses.Referred to herein as source database in not
Labeled data to be synchronized, can be true according to the business demand of reality by the designer or system manager of this programme
It is fixed, such as:Data related to marked data in unlabelled data can be defined as to data to be synchronized, with having marked
The related data of the data of note can be and the business identical data belonging to marked data.In other examples, may be used also
So that business datum important in unlabelled data, the business datum that may be accessed repeatedly etc. are defined as into number to be synchronized
According to this specification embodiment is without limitation.
After target database is switched into the database that the operation system preferentially accesses, it is contemplated that the target newly switched
The database not stable operation under the actual operating environment of operation system, in fact it could happen that failure, and then traffic affecting and
When handle, in order to avoid influence of the failure to business of target database, there are data to write in scheduled time slot that can be after handover
It is data to be synchronized by the data markers write, when reaching predetermined lock in time, to source database when entering target database
The data being labeled in synchronous target database.Referred to herein as the scheduled time can be by this programme designer or business pipe
Reason personnel set according to business demand, are such as set as 1 hour, 1 day or other periods.
The new data in target database is synchronized to source database in scheduled time slot, target database can be worked as in institute
State in scheduled time slot when there is abnormal operating condition, source database is switched into the data that the operation system preferentially accesses again
Storehouse.Then it is data to be synchronized by the data markers write again when there is data to write source database;Reach predetermined same
When walking the time, labeled data, the quilt into target database synchronization source database into source database synchronization target database
The data of mark;After the data being labeled in source database are synchronized to target database, target database is switched to again
The database that the operation system preferentially accesses.Pass through database switchback during failure, operation system and target data can be made
Storehouse can preferably coordinate operation, avoid influence of the failure to business behind switch data storehouse, and also allow in time to target data
Storehouse is adjusted, and can effectively reduce the rate of breakdown of target database, and then improve business processing efficiency.
, both can be into source database synchronization target database in the data being synchronously labeled due to the switchback of database
Data, also can be to the data in target database synchronization source database, in order to avoid same business datum is back and forth in different numbers
According to synchronous between storehouse, in synchronously labeled any group of data, by this group of data by the high database synchronization of optimistic lock version to
The low database of optimism lock version.
In other examples, it can also circulate and perform switchback database, mark data to be synchronized, be same to target database
The step of step data, switching target database are the database that the operation system preferentially accesses, until target database is in institute
State and abnormal operating condition is occurred without in scheduled time slot.
In addition, if target database does not occur abnormal operating condition in the scheduled time slot, source can be directly abandoned
Database.But in order to avoid target database breaks down within the short time after the scheduled time slot, influence at business
Reason, can be selectively by the data syn-chronization write to source when having data write-in target database after the scheduled time slot
Database, in some examples, when there can be the data to write target database after the scheduled time slot, obtain current time pair
The data to be synchronized answered, wherein, current time and the time gap of the scheduled time slot are bigger, and corresponding data to be synchronized are got over
It is few;It is data to be synchronized by the data markers write during corresponding with the current time Data Matching to be synchronized of the data of write-in.
It data to be synchronized corresponding to current time, can be preset by this programme personnel, be treated for different time settings is different
Synchrodata, such as:The importance of data is poorer, and the corresponding time is fewer, so can slowly reduction flag it is to be synchronized
The amount of data, until no longer marking data to be synchronized.
After switching to the database that operation system preferentially accesses, when target database breaks down in scheduled time slot
When, source database can be switched to the database that operation system preferentially accesses, the data to be synchronized of mark are all synchronous again
To after target database, target database can be switched into the database that operation system preferentially accesses again again.Therefore, at least one
The database that operation system preferentially accesses in the section time is not fixed, then during this period of time, Operation Server is likely to be received
For the multiple service request (repeatedly request belongs to same business) of same business, first time, service request was in source database and mesh
Being received before mark database switching, Operation Server 105 responds the first time service request, and corresponding operating is performed to source database,
The status data of the business is updated to 1.After replacing source database with target database, target database turns into Operation Server
The database preferentially accessed, second of service request are sent to Operation Server, and Operation Server responds second of business please
Ask, corresponding operating is performed to target database, the status data of the business is updated to 2.
In summary, Operation Server responds service request twice, and disparate databases are performed with operation, can cause two
The data of same business are inconsistent in database, and the data of the flowing water type of same business are consistent in disparate databases, easily go out
Existing idempotent failure, causes user to provide damage.This specification embodiment, can be in the data of write-in source database in order to solve the problem
When being flowing water type data, the business belonging to the data of said write and database purchase are recorded to predetermined business operation, its
In, affiliated database is source database.
In addition, the data for belonging to same business record once in business operation record, and can be to solve the above problems, institute
Before being recorded with the business belonging to data to be written and database purchase to predetermined business operation, the business behaviour can be transferred
Note down;Judge the business and database belonging to the data of said write whether are recorded in the business operation record;Institute
State in business operation record when there is no the business and database belonging to the data of said write, then by belonging to the data of said write
Business and database recorded predetermined business operation record.In addition, in order to reduce the idempotent problem between disparate databases,
Can be by the business operation record storage in target database, so without ensureing that business operation is remembered by other measures again
Idempotence where record between database and target database.
In addition to flowing water type data, it is also possible to which the data for having non-flowing water type need to write target database or source database, non-
Flowing water type data can refer to status data, may be frequently changed, right such as the accounting data of the remaining sum in electronic account etc
In non-flowing water type data, if a part of data distribution of same business, in target database, another part data distribution exists
In source database, the business processing that can cause to be related to non-flowing water type data reports an error, therefore, in switching source database or target every time
In a period after the database that database preferentially accesses for operation system, if necessary to operate primary database, primary database is
It is another in the database preferentially accessed by the operation system in source database and target database, source database and target database
One database is from database, can determine operation strategy based at least one of following before primary database is operated:
The data type of data to be operated, the business belonging to data to be operated, predetermined business operation record;According to
Identified operation strategy performs corresponding operating to primary database.
Wherein, the business operation records the business and database belonging to the data for including having operated;Identified operation
Strategy is the strategy for forbidding performing primary database corresponding operating, or allows the strategy that corresponding operating is performed to primary database.
The database of its preferential access may be performed repeatedly in addition, it is contemplated that Operation Server responds single service request
Operation, if the operation strategy of multi-pass operation is different, it is consistent to be easily caused the data of same business in disparate databases, therefore,
When performing corresponding operating to primary database according to identified operation strategy, if the service request of each operation response is identical,
To primary database perform each operation when institute according to operation strategy it is identical, this identical operation strategy can be in response to the business
Before request performs operation first to primary database, according to the industry belonging to the data type of data to be operated, data to be operated
Operation strategy determined by least one in business and predetermined business operation record.
It is determined that during operation strategy, during application scenarios difference, determine that the content of operation strategy institute foundation is different, be exemplified below
Several application scenarios, and determine the mode of operation strategy:
Scene one:The data that business under the scene is related to are non-flowing water type data, or are needed under the scene to main number
When the operation performed according to storehouse is read operation or locks operation, it can determine to operate according only to the business belonging to data to be operated
Strategy.Referred to herein as operation can be write operation, read operation and lock operation any of, write operation can be insertion behaviour
Any of work, deletion action and modification operation.
When according to the business belonging to data to be operated to determine operation strategy, it can receive or examine from Operation Server
In the content that the service request that measures carries, the targeted business of the service request is obtained, the service request is responded and needs to operate
Data, be the business belonging to the data that need to operate by the business of acquisition, then judge the number for belonging to the business from database
According to whether it is fully synchronized arrive primary database, if it is, identified operation strategy can be allow to primary database perform phase
The strategy that should be operated;If it is not, then identified operation strategy can be the strategy for forbidding performing primary database corresponding operating.
When reality judges, the synchronous mark for the data for belonging to the business can be inquired about in the synchrodata table from database
Note, if found, it is determined that it is not fully synchronized to primary database to belong to the data of the business from database, if do not searched
Arrive, the business can also be being searched for from database, is searching this according to the index of the business or the index of data to be operated
After business, judge whether the data of the business have been synchronized to primary database, if it is not, then determining to belong to the industry from database
The data of business are not fully synchronized to arrive primary database, if it is, determining that the data for belonging to the business from database are all same
Walk primary database.
In other embodiments, when determining operation strategy, it can first judge that original SQL corresponding with on-unit is looked into
Whether inquiry condition is included as the unique index of data configuration to be operated, if comprising according to the unique index, inquiring about from number
Whether primary database is synchronized to according to the data of the business in storehouse, if it is, identified operation strategy can be allowed pair
Primary database performs the strategy of corresponding operating, if not, identified operation strategy can be progress performs phase to primary database
The strategy that should be operated.
If original SQL query condition does not include the unique index for data configuration to be operated, judge that original SQL is looked into
Whether the major key ID configurations of inquiry condition are empty, if it is, determining the querying condition that the SQL query condition is batch operation, then
According to the table name of synchrodata table and sync mark inquiry, whether the data of the business from database have been synchronized to master data
Storehouse, if not, identified operation strategy can be the strategy that progress performs corresponding operating to primary database, if it is, institute is really
Fixed operation strategy can be the strategy for allowing to perform primary database corresponding operating.
If the major key ID configurations of original SQL query condition are not sky, according to major key ID inquiries industry from database
Whether the data of business are empty, if it is not, then whether the data for judging to be inquired according to major key ID have been synchronized to primary database,
If it is, identified operation strategy can be the strategy for allowing to perform primary database corresponding operating, if not, identified
Operation strategy can be the strategy that progress performs corresponding operating to primary database.
If being empty according to major key ID inquiries data of the business from database, looked into according to where querying conditions are counter
From the traffic table of database, the unique index for whether including the affiliated business of data to be operated in the traffic table is judged, if
Do not include, it is determined that the SQL query condition is the querying condition of batch operation, then according to the table name of synchrodata table and synchronous mark
Whether note inquiry data of the business from database have been synchronized to primary database, if it is, identified operation strategy can
To be the strategy for allowing to perform primary database corresponding operating, if not, identified operation strategy can be in progress to main number
The strategy of corresponding operating is performed according to storehouse.
If the traffic table includes the unique index of the affiliated business of data to be operated, read from the traffic table
The unique index of the affiliated business of data of extract operation, then according to the unique index, inquire about the data of the business from database
Whether primary database has been synchronized to, if it is, identified operation strategy can allow to perform primary database corresponding behaviour
The strategy of work, if not, identified operation strategy can be the strategy that progress performs corresponding operating to primary database.
During above-mentioned determination operation strategy, if identified operation strategy is to forbid performing phase to primary database
It should operate, identified operation strategy can be represented by throwing mistake.Operation if necessary to be performed to primary database is grasped for reading
Make, then when identified operation strategy is forbids performing corresponding operating to primary database, this specification embodiment, Ke Yiyun
Perhaps Operation Server reads the data from database.
Under other scenes, the operation if necessary to be performed to primary database is write operation, the number of primary database to be written
According to being probably flowing water type data, it is also possible to during non-flowing water type data, it is determined that during operation strategy, can judge with it is pending
Operation corresponding to before whether original SQL query condition be included as the unique index of data configuration to be operated, first determine to wait to grasp
The data type of the data of work, if non-flowing water type data, then judge original SQL query bar corresponding with on-unit
Whether part is included as the unique index of data configuration to be operated, if flowing water type data, then according to data institute to be operated
The business of category and predetermined business record table, to determine operation strategy.
Scene two:The existing non-flowing water type data of data that business under the scene is related to, there is flowing water type data, Ke Yigen again
Operation strategy is determined according to the data type of data to be operated and the business belonging to it, can also be simultaneously according to number to be operated
According to data type, the business belonging to it and predetermined business operation record determine operation strategy.
In the business belonging to the data type according to data to be operated and its, it is not flowing water type to judge data to be operated
Data, and the data from database with the data to be operated with business, it is identified when being synchronized to primary database entirely
Operation strategy can be the strategy for allowing to perform primary database corresponding operating.
In the business and data type according to belonging to data to be operated, it is not flowing water type number to judge data to be operated
According to, and the data from database with the data to be operated with business, when not being synchronized to primary database entirely, identified behaviour
It can be the strategy for forbidding performing primary database corresponding operating to make strategy.
Recorded in the data type according to data to be operated, the business belonging to it and predetermined business operation, judge to treat
The data of operation are flowing water type data, and when there is no the business belonging to the data to be operated in business operation record,
Identified operation strategy can be the strategy for allowing to perform primary database corresponding operating.
Judging that data to be operated are flowing water type data in addition, and having in business operation record described to be operated
During business belonging to data, whether the data for determining whether to belong to the business in the business operation record belong to master data
Storehouse, if belonged to, identified operation strategy can be the strategy for allowing to perform primary database corresponding operating.
If the data for belonging to the business in the business operation record belong to from database, can be further by treating
Business belonging to the data of operation, judge whether the data for belonging to the business from database are fully synchronized to primary database,
If fully synchronized arrive primary database, identified operation strategy can be the plan for allowing to perform primary database corresponding operating
Slightly, if not fully synchronized arrive from database, identified operation strategy can forbid performing corresponding operating to primary database
Strategy.
During above-mentioned determination operation strategy, if data to be operated are flowing water type data, logarithm can needed
When the operation performed according to storehouse is write operation, according to the data type of data to be operated, the business belonging to it and predetermined business
Operation note determines operation strategy, and the operation forbidden is write operation.
In addition, data to be operated are flowing water type data, identified operation strategy is to allow to perform phase to primary database
It should operate, after corresponding operating is performed to primary database, the business belonging to operated data can be arrived with data-base recording
The business operation record, wherein, affiliated database is primary database.It so can conveniently be directed to the data of flowing water type next time
Carry out the determination of operation strategy.
, can be according to be operated affiliated if the data that business is related to only have flowing water type data under other scenes
Business and predetermined business operation are recorded to determine operation strategy, and specific determination mode can refer to the determination side of above-described embodiment
Formula, it will not be repeated here.
Below in conjunction with accompanying drawing 3 to 6, in the case where being related to illustrating under the business scenario of database switching, service switchover system
Unite preferentially access database it is front and rear, how to handle the write operation of flowing water type data.Flowing water type data can refer to electronics account
The business datum of family flowing water, order data etc, the business being related to have the dynamic process as flowing water.
In each business scenario shown in Fig. 3 to 6, including two databases, one of them is database Master, another
Individual is database Slave, and transaction log is blacklist, for recording the business (service request belonging to the data operated
For business), the affiliated database database of operation (response service request), the mark of data to be synchronized is in same step number
According in table, according to the content recorded in the synchrodata table, it may be determined that go out data to be synchronized.
Referring to Fig. 3, in scene shown in Fig. 3, database Master is source database, is that Operation Server preferentially accesses
Initial data base, database Slave is target database, can be specifically database Master redundancy backup database or
Migrating data storehouse, the data in database Master do not have started synchronous to database Slave, do not generate business processing note yet
Record (blacklist).
In practical application, if user logs in client in client device, and sent out by client to Operation Server
Send the first service request (step 301) for business A:Business A state is set to 1, Operation Server receives the business
After request, Operation Server can write the data (step S302) for business A state to be set to 1 to database Master:
Represent that " business A state is 1 " character string.Then, for later stage synchrodata, the data of write-in can be marked, generate Fig. 3
Shown in synchrodata table 31.Because the data in database Master do not have started, operation clothes synchronous to database Slave
Business device does not also perform operation to database Slave, so database Slave synchrodata is sky, table as shown in Figure 3
32。
In addition, in order to receive again judge during business A service request this operation be database Master, can
By business A mark A and Database Identification Master corresponding records, to generate the blacklist as shown in table 33 in Fig. 3, be stored in
Database Slave.
Referring to Fig. 4, in scene shown in Fig. 4, database Master is source database, is that Operation Server preferentially accesses
Initial data base, database Slave is target database, can be specifically database Master redundancy backup database or
Migrating data storehouse, database Master are stored with the data syn-chronization record generated in embodiment corresponding to Fig. 3, as shown in Figure 4
Table 41, according to table 41 by database Master at least part data syn-chronization to database Slave, database Slave is fortune
The database that battalion's server currentization preferentially accesses, is stored with the blacklist generated in embodiment corresponding to Fig. 3, as shown in Figure 4
Table 42.
In practical application, if user logs in client in client device, and sent out by client to Operation Server
Send the first service request (step 401) for business B:Business B state is set to 1, Operation Server receives the business
After request, Operation Server can transfer the blacklist (step 402) shown in table 42 from database Slave, then judge what is transferred
It whether there is business B (steps 403) in blacklist, judged result is in the absence of can be write to database Slave for by industry
Business B state is set to 1 data (step S404):Represent that " business B state is 1 " character string.Then, in order to which the later stage is synchronous
Data, the data of write-in can be marked, generate the synchrodata table 43 shown in Fig. 4.
In addition, in order to receive again judge during business B service request this operation be database Slave, can
By business B mark B and Database Identification Slave corresponding records, to generate the blacklist as shown in table 44 in Fig. 4.
Referring to Fig. 5, in scene shown in Fig. 5, database Master is source database, is that Operation Server preferentially accesses
Initial data base, database Slave is target database, can be specifically database Master redundancy backup database or
Migrating data storehouse, database Master are stored with the data syn-chronization record generated in embodiment corresponding to Fig. 3, as shown in Figure 5
Table 51, according to table 51 by database Master at least part data syn-chronization to database Slave, database Slave is fortune
The database that preferentially accesses of battalion's server currentization, be stored with the synchrodata generated in embodiment corresponding to Fig. 4 record with it is black
List, difference table 52 and table 53 as shown in Figure 5.
In practical application, if user logs in client in client device, and sent out by client to Operation Server
Send the second service request (step 501) for business A:Business A state is set to 2, Operation Server receives the business
After request, Operation Server can transfer the blacklist (step 502) shown in table 53 from database Slave, then judge what is transferred
Whether there is business A in blacklist, and in the presence of corresponding server identification whether be Slave (steps 503), judged result
It is business A be present, corresponding server identification is not Slave, now, does not allow Operation Server to be write to database Slave
For business A state to be set to 2 data, then refuse the service request (step S504).
Under other scenes, if database Master is the database that Operation Server initialization preferentially accesses, data
Storehouse Slave is database Master redundancy backup database or migrating data storehouse, and database Master is stored with corresponding to Fig. 3
The data syn-chronization record generated in embodiment, table 51 as shown in Figure 5 need to be same by all of database Master according to table 51
The data syn-chronization of step is to database Slave, then though business A in the blacklist transferred be present, and server corresponding to business A
Mark is not Slave, allows Operation Server to write the data for business A state to be set to 2 to database Slave yet.
Referring to Fig. 6, in scene shown in Fig. 6, database Master is source database, is that Operation Server preferentially accesses
Initial data base, database Slave is target database, can be specifically database Master redundancy backup database or
Migrating data storehouse, the data syn-chronization record generated in the embodiment according to corresponding to Fig. 3, by database Master at least part
Data syn-chronization is to database Slave.
Database Slave is stored with corresponding to Fig. 4 and implemented after the database for switching to Operation Serverization preferentially to access
The blacklist and synchrodata generated in example records, respectively table 62 and table 63 as shown in Figure 6, the data according to table 63
Synchronous recording, by database Slave at least part data syn-chronization to database Master, after switching again, database
Master is the database that Operation Server current preference accesses.
In practical application, if user logs in client in client device, and sent out by client to Operation Server
Send the second service request (step 601) for business A:Business A state is set to 2, Operation Server receives the business
After request, Operation Server can transfer the blacklist (step 602) shown in table 62 from database Slave, then judge what is transferred
Whether there is business A in blacklist, and in the presence of corresponding server identification whether be Master (steps 603), judge to tie
Fruit is business A be present, and corresponding server identification is not Master, and now, Operation Server can be write to database Master
Enter the data (step S604) for business A state to be set to 2:Represent that " business A state is 2 " character string.Then, it is
Later stage synchrodata, the data of write-in can be marked, generate the synchrodata table 61 shown in Fig. 6.
Further, since also go request record in existing business A and this operation be database mark Master, can
Not modified to blacklist.
, can be by data when meeting predetermined timing condition for the application scenarios any one of Fig. 3 to Fig. 6
Marked data syn-chronization is into database Slave in the Master of storehouse, or, data marked in database Slave are same
Walk in database Master.
If in addition, need to realize the business of idempotent when business A or business B, can allowing to database Master or
Before database Slave carries out operation corresponding with service request, judge whether to receive the service request first, if it is permit
Perhaps it is corresponding with service request to database Master or database Slave progress to operate, if it is not, then forbidding to database
Master or database Slave carries out operate corresponding with service request.
From above-described embodiment:The data handover scheme that this specification provides, can both realize same business in each number
It is consistent according to the data in storehouse, it can also be ensured that the business idempotent in database handoff procedure.
Corresponding with the embodiment of preceding method, this specification additionally provides the embodiment of device.
Referring to Fig. 7, Fig. 7 is the block diagram of the database switching device shown in the exemplary embodiment of this specification one, the device
It can include:Data markers module 710, data simultaneous module 720 and database handover module 730.
Wherein, data markers module 710, for being to treat by the data markers write when there is data to write source database
Synchronous data, wherein, source database is the database that operation system preferentially accesses.
Data simultaneous module 720, for when reaching predetermined lock in time, into target database synchronization source database
Labeled data.
Database handover module 730, will after the data for being labeled in source database are synchronized to target database
Target database switches to the database that the operation system preferentially accesses.
In some examples, the database switching device of this specification embodiment can also include:
Depth synchronization module, after the data for being labeled in source database are synchronized to target database, to target
The data to be synchronized not being labeled in database synchronization source database;
Database handover module 730 can be also used for:
After labeled data to be synchronized are not synchronized to target database in source database, target database is switched
The database preferentially accessed for the operation system.
In other examples, the database switching device of this specification embodiment can also include:
Succeeding marker module, for switch to the operation system preferentially to access in target database database after it is pre-
It is data to be synchronized by the data markers write when having data write-in target database in timing section.
Subsequent synchronisation module, for when reaching predetermined lock in time, the quilt into source database synchronization target database
The data of mark.
In other examples, the database switching device of this specification embodiment can also include:
Data type acquisition module, for not occurring abnormal operating condition in the scheduled time slot in target database,
And when having data write-in target database after the scheduled time slot, data to be synchronized corresponding to current time are obtained, wherein, currently
Time and the time gap of the scheduled time slot are bigger, and corresponding data to be synchronized are fewer.
Supplemental markers module, during corresponding with the current time Data Matching to be synchronized of data for writing, by what is write
Data markers are data to be synchronized.
In other examples, the database switching device of this specification embodiment can also include fault switch module, double
To synchronization module and database switchback module:
The failure tackles module, for when there is abnormal operating condition in the scheduled time slot in target database,
Again source database is switched into the database that the operation system preferentially accesses, and notifies the data simultaneous module to be still used for
It is data to be synchronized by the data markers write when there is data to write source database.
The bi-directional synchronization module, for reaching predetermined lock in time constantly, to source database synchronization target data
The data being labeled in storehouse, the data being labeled into target database synchronization source database.
The database switchback module, after the data for being labeled in source database are synchronized to target database,
Again target database is switched into the database that the operation system preferentially accesses.
As an example, the bi-directional synchronization module is additionally operable in any group of data being synchronously labeled, by this group of data
By the high database synchronization of optimistic lock version to the low database of optimistic lock version.
In other examples, source database is oracle database, and target database is OceanBase databases.
In other examples, the database switching device of this specification embodiment can also include:
Business record module, for when the data of write-in are flowing water type data, by the industry belonging to the data of said write
Business and database purchase record to predetermined business operation, wherein, affiliated database is source database.
In other examples, the database switching device of this specification embodiment can also include:
Record transfers module, in the business belonging to the data by said write and database purchase to predetermined business
Before operation note, the business operation record is transferred;
Judge module is recorded, for judging whether recorded in the business operation record belonging to the data of said write
Business and database;
The business record module, for not having the business belonging to the data of said write in business operation record
During with database, the business belonging to the data of said write and database be recorded into predetermined business operation and recorded.
As an example, the business operation record storage is in target database.
In other examples, the database switching device of this specification embodiment can also include:
Tactful determining module, for switch to the operation system preferentially to access in target database database after, it is main
Before database is operated, operation strategy is determined based at least one of following:
The data type of data to be operated, the business belonging to data to be operated, predetermined business operation record;
Operation executing module, corresponding operating is performed to primary database for the operation strategy determined by;
Wherein, the database preferentially accessed by the operation system in source database and target database is primary database,
Another database is from database;
The business operation records the business and database belonging to the data for including having operated;
Identified operation strategy is:
Forbid performing primary database the strategy of corresponding operating;Or,
Allow the strategy that corresponding operating is performed to primary database.
As an example, from database with the data to be operated with the data of business, be synchronized to primary database entirely
When, identified operation strategy is the strategy for allowing to perform primary database corresponding operating;
Data from database with the data to be operated with business, when not being synchronized to primary database entirely, are determined
Operation strategy be forbid to primary database perform corresponding operating strategy.
As an example, data to be operated are not flowing water type data, and same with the data to be operated from database
The data of business, when being synchronized to primary database entirely, identified operation strategy is to allow to perform corresponding operating to primary database
Strategy;
Data to be operated are not flowing water type data, and the number from database with the data to be operated with business
According to when not being synchronized to primary database entirely, identified operation strategy is the strategy for forbidding performing primary database corresponding operating.
As an example, data to be operated are flowing water type data, and are not had in business operation record described to be operated
Data belonging to business when, identified operation strategy be allow to primary database perform corresponding operating strategy;
The database switching device of this specification embodiment can also include:
First logging modle, for after primary database is performed corresponding operating, by the business belonging to operated data
Primary database recorded the business operation record, wherein, affiliated database is primary database.
As an example, data to be operated are flowing water type data, have the number to be operated in the business operation record
When belonging to the data of the business according to affiliated business, and in business operation record and being not belonging to primary database, identified behaviour
Make strategy to forbid performing primary database the strategy of corresponding operating;
Data to be operated are flowing water type data, there is the industry belonging to the data to be operated in the business operation record
Business, and when belonging to the data of the business in business operation record and belonging to primary database, identified operation strategy is fair
Perhaps the strategy of corresponding operating is performed to primary database;
The database switching device of this specification embodiment can also include:
Second logging modle, for after primary database is performed corresponding operating, by the business belonging to operated data
Recorded with data-base recording to the business operation, wherein, affiliated database is primary database.
As an example, data to be operated are flowing water type data, have the number to be operated in the business operation record
According to affiliated business, the data that the business is belonged in business operation record are not belonging to primary database, and from database with
The data to be operated are with the data of business, and when not being synchronized to primary database entirely, identified operation strategy is to forbid to master
Database performs the strategy of corresponding operating;
Data to be operated are flowing water type data, and being recorded in the business operation record has belonging to the data to be operated
Business, the data that the business is belonged in business operation record are not belonging to primary database, and are treated from database with described
The data of operation are with the data of business, and when being synchronized to primary database entirely, identified operation strategy is to allow to hold primary database
The strategy of row corresponding operating;
The database switching device of this specification embodiment can also include:
3rd logging modle, for after primary database is performed corresponding operating, by the business belonging to operated data
Recorded with data-base recording to the business operation, wherein, affiliated database is primary database.
As an example, the business operation record storage is from database.
As an example, if data to be operated are flowing water type data, the operation forbidden is write operation.
As an example, the database switching device of this specification embodiment can also include:
Data read module, for when the operation forbidden is read operation, it is allowed to from database to the number to continue
According to progress read operation.
As an example, the operation executing module is additionally operable to:
When the service request of each operation response is identical, each operation is performed to primary database according to identical operation strategy;
Before the operation strategy is responds the service request to primary database execution operation first, according to data to be operated
Data type, in the business belonging to data to be operated and predetermined business operation record at least one of determined by operate
Strategy.
The function of unit (or module) and the implementation process of effect specifically refer to right in the above method in said apparatus
The implementation process of step is answered, will not be repeated here.
For device embodiment, because it corresponds essentially to embodiment of the method, so related part is real referring to method
Apply the part explanation of example.Device embodiment described above is only schematical, wherein described be used as separating component
The unit or module of explanation can be or may not be physically separate, and the part shown as unit or module can be with
It is or may not be physical location or module, you can with positioned at a place, or multiple network lists can also be distributed to
In member or module.Some or all of module therein can be selected to realize the mesh of this specification scheme according to the actual needs
's.Those of ordinary skill in the art are without creative efforts, you can to understand and implement.
The embodiment of this specification device can be applied on a computing device.Specifically can be by computer chip or entity
Realize, or realized by the product with certain function.In a kind of typical realization, computer equipment is computer, is calculated
The concrete form of machine can be personal computer, laptop computer, personal digital assistant, media player or these equipment
In any several equipment combination.
Device embodiment can be realized by software, can also be realized by way of hardware or software and hardware combining.With
Exemplified by software is realized, as the device on a logical meaning, being will be non-volatile by the processor of computer equipment where it
Property the computer-readable recording medium such as memory in corresponding computer program instructions read what operation in internal memory was formed.From hardware view
Speech, as shown in figure 8, being a kind of hardware structure diagram of this specification device place computer equipment, except the processing shown in Fig. 8
Outside device, internal memory, network interface and nonvolatile memory, computer equipment in embodiment where device generally according to
The actual functional capability of the computer equipment, other hardware can also be included, this is repeated no more.
In one example, the memory of computer equipment can store processor executable program instructions;Processor can
With coupled memory, for reading the programmed instruction of the memory storage, and as response, following operation is performed:There is number
It is data to be synchronized by the data markers write during according to write-in source database, wherein, source database is that operation system is preferentially visited
The database asked;If reaching predetermined lock in time, the data being labeled into target database synchronization source database;Source number
After being synchronized to target database according to the data being labeled in storehouse, the operation system is switched to preferentially to access target database
Database.
In other embodiments, the operation performed by processor may be referred to description related in embodiment of the method above,
It will not be described here.
It is above-mentioned that this specification specific embodiment is described.Other embodiments are in the scope of the appended claims
It is interior.In some cases, the action recorded in detail in the claims or step can be come according to different from the order in embodiment
Perform and still can realize desired result.In addition, the process described in the accompanying drawings not necessarily require show it is specific suitable
Sequence or consecutive order could realize desired result.In some embodiments, multitasking and parallel processing be also can
With or be probably favourable.
The preferred embodiment of this specification is the foregoing is only, it is all in this explanation not to limit this specification
Within the spirit and principle of book, any modification, equivalent substitution and improvements done etc., the model of this specification protection should be included in
Within enclosing.