CN102955851A - Database switching method and device - Google Patents

Database switching method and device Download PDF

Info

Publication number
CN102955851A
CN102955851A CN 201210425127 CN201210425127A CN102955851A CN 102955851 A CN102955851 A CN 102955851A CN 201210425127 CN201210425127 CN 201210425127 CN 201210425127 A CN201210425127 A CN 201210425127A CN 102955851 A CN102955851 A CN 102955851A
Authority
CN
China
Prior art keywords
database
available
operation layer
instance
available flag
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN 201210425127
Other languages
Chinese (zh)
Other versions
CN102955851B (en
Inventor
李连港
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Qizhi Business Consulting Co ltd
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo Technology Co Ltd
Qizhi Software Beijing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Qihoo Technology Co Ltd, Qizhi Software Beijing Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201210425127.9A priority Critical patent/CN102955851B/en
Publication of CN102955851A publication Critical patent/CN102955851A/en
Application granted granted Critical
Publication of CN102955851B publication Critical patent/CN102955851B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a database switching method and a database switching device, wherein the method comprises the following concrete steps that a database instance of associated container storage service is adopted, and the database instance in an associated container is marked to be available during storage; when a call request from a business layer is received, connection between a master database and the business layer is established; the database instance with an available mark is selected from the associated container; connection between a corresponding database of the selected database instance and the business layer is established; and when abnormal connecting times of the database and the business layer is captured to be greater than a first threshold, the available mark of the corresponding database instance in the associated container is changed to be unavailable. According to the database switching method and the database switching device, the processing and concurrent efficiency of a database system can be increased, and system overhead and waste of resources can be reduced.

Description

A kind of switching method and apparatus of database
Technical field
The present invention relates to database technical field, be specifically related to a kind of switching method and apparatus of database.
Background technology
Some technology of data copies that database itself provides typically refer to the architecture that database itself provides a kind of management, monitoring and automatically moves, and are suitable for creating and safeguarding one or more backup databases.Generally be in physical level and logic level, by transmission and runtime database journal file, keep producing the data consistency with backup database.In case master data base is because of certain situation when unavailable, backup database will switch to new master data base, to reach the purpose without database loss or minimise data loss.
The flow process of existing a kind of database system switching method specifically can comprise:
Step 1, primary and backup machine agency carries out the same database operation to database instance separately and finishes and copy by intercepting simultaneously the database manipulation packet of broadcasting in the Ethernet;
Step 2, database instance return Cheng Gong to the correspondence agency and unsuccessfully indicate;
Step 3, main computer agency takes defeat and indicates and the guest machine agency receives and successfully indicates, and is then acted on behalf of by main computer agent advertisement guest machine and carries out active and standby switching;
Step 4, utilize message authentication mechanism and switch timer and carry out the active and standby switching of Database Systems.
Prior art has following defective:
1, with broadcast mode the database manipulation bag is issued primary and backup machine agency and finish data Replica, increased the weight of system's distribution load, prolonged system's treatment scheme, cause easily the waste of system overhead, affect the concurrent efficient of system;
2, utilize message authentication mechanism to carry out the active and standby switching of Database Systems, cause easily in certain timing time the message queuing of blocking up, a large amount of requests waits can be caused in the request peak period, have reduced the treatment effeciency of system;
3, active and standby machine respectively has the agency of oneself, and practical function is similar, causes easily system redundancy and the wasting of resources.
In a word, need the urgent technical matters that solves of those skilled in the art to be exactly: how can improve processing and the concurrent efficient of Database Systems, and, reduce system overhead and the wasting of resources.
Summary of the invention
In view of the above problems, the present invention has been proposed in order to a kind of switching method and apparatus of the database that overcomes the problems referred to above or address the above problem at least in part is provided.
According to one aspect of the present invention, a kind of changing method of database is provided, comprising:
Adopt the database instance of associative container stores service, the available flag of database instance when storage is available in the described associative container;
When receiving the call request of operation layer, set up being connected of master data base and described operation layer;
Choosing available flag from described associative container is available database instance;
Set up being connected of selected database instance correspondence database and described operation layer;
When capturing database unusual number of times is greater than first threshold with being connected of described operation layer, be revised as the available flag of associated databases example in the described associative container unavailable.
Alternatively, described method also comprises:
Whether the available flag that infinite loop is surveyed database instance in the described associative container is available, if unavailable, then send alarm, be that database corresponding to disabled database instance safeguard according to described alarm to described available flag by the data base administrator, and after maintenance is finished, in the look-up table of database, be set to the available flag of described database available; Described look-up table is corresponding one by one with database, is suitable for the available flag of stored data base;
Be disabled database instance for described available flag, but the available flag of database it is the time spent in detecting the look-up table of its correspondence database, is revised as its available flag available in described associative container.
Alternatively, described method also comprises:
For database, record the number that it is connected with described operation layer;
Before setting up being connected of selected database instance correspondence database and described operation layer, judge that whether number that described database is connected with described operation layer is greater than Second Threshold, if then send alarm, otherwise, set up being connected of described database and described operation layer.
Alternatively, described method also comprises:
Carry out in the processing procedure of current affairs in described operation layer institute connection data storehouse, with described operation layer institute connection data storehouse as master data base, with the renewal data Replica of described master data base to from database;
Wait for a plurality ofly after at least one copies successfully from database in described master data base, carry out the processing of next affairs.
Alternatively, described method also comprises:
In stand-by period during greater than the time-out time threshold value, a plurality of at least one copies successful wait from database for described to stop described master data base, and carries out the processing of next affairs.
Alternatively, obtain as follows the database instance of the service of storing in the described associative container:
When service starts, obtain the database instance of service according to the operating system environment variable;
Adopt database connection pool to deposit fetched data storehouse example and corresponding the connection;
For connecting normal database instance in the described database connection pool, its available flag is set to available, and insert in the corresponding associative container.
According to a further aspect in the invention, provide a kind of switching device shifter of database, having comprised:
Associative container is suitable for the database instance of stores service, and the available flag of database instance when storage is available in the described associative container;
First connects and to set up module, is suitable for when receiving the call request of operation layer, sets up being connected of master data base and described operation layer;
Example is chosen module, and being suitable for choosing from described associative container available flag is available database instance;
Second connects and to set up module, is suitable for setting up being connected of selected database instance correspondence database and described operation layer; And
The sign modified module is suitable for when capturing database unusual number of times is greater than first threshold with being connected of described operation layer, is revised as the available flag of associated databases example in the described associative container unavailable.Alternatively, described device also comprises:
The loop detection module, whether the available flag that is suitable for database instance in the described associative container of loop detection is available;
The first warning reminding module, when the available flag that is suitable for database instance in detecting described associative container is unavailable, send alarm, be that database corresponding to disabled database instance safeguard according to described alarm to described available flag by the data base administrator, and after maintenance is finished, in the look-up table of database, be set to the available flag of described database available; Described look-up table is corresponding one by one with database, is suitable for the available flag of stored data base;
Look-up table detects modified module, and being suitable for for described available flag is disabled database instance, but the available flag of database is the time spent in detecting the look-up table of its correspondence database, is revised as its available flag available in described associative container.
Alternatively, described device also comprises:
The linking number logging modle is suitable for for database, records the number that it is connected with described operation layer;
The linking number judge module, be suitable for described second connect set up module and set up being connected of selected database instance correspondence database and described operation layer before, judge that whether number that described database is connected with described operation layer is greater than Second Threshold;
The second warning reminding module when being suitable for the number that is connected with described operation layer at described database greater than Second Threshold, sends alarm;
Described second connects and to set up module, when also specifically being suitable for the number that is connected with described operation layer at described database less than or equal to Second Threshold, sets up being connected of described database and described operation layer.
Alternatively, described device also comprises:
The leader follower replication module is suitable for carrying out in the processing procedure of current affairs in described operation layer institute connection data storehouse, with described operation layer institute connection data storehouse as master data base, with the renewal data Replica of described master data base to from database;
Wait for module, be suitable for waiting in described master data base a plurality of after at least one copies successfully from database, carry out the processing of next affairs.
Alternatively, described device also comprises:
Wait for stopping modular, be suitable in stand-by period during greater than the time-out time threshold value that a plurality of at least one copies successful wait from database for described to stop described master data base, and carries out the processing of next affairs.
Alternatively, described device also comprises: the container instance acquisition module that is suitable for obtaining the database instance of the service of storing in the described associative container;
Described container instance acquisition module comprises:
Service Instance obtains submodule, is suitable for obtaining the database instance of service according to the operating system environment variable when service starts;
Database connection pool is suitable for depositing fetched data storehouse example and corresponding the connection;
The intron module is suitable for connecting normal database instance in the described database connection pool, its available flag is set to available, and inserts in the corresponding associative container.
Obtained following beneficial effect according to the switching method and apparatus of database of the present invention:
The present invention is when receiving the call request of operation layer, acquiescence is set up being connected of master data base and described operation layer, and, if the available flag of master data base correspondence database example is unavailable, then set up being connected of availability database example correspondence database and described operation layer; As seen, the present invention can be by to set up available flag be available database instance correspondence database and being connected of described operation layer, realize master-slave database efficient, switch in real time;
1, active and standby machine respectively has oneself agency in the prior art, and practical function is similar, causes easily system redundancy and the wasting of resources; And the present invention carries out unified agent to all database instances of serving, and like this, peel off in database broker of the present invention and principal and subordinate storehouse, can form public database broker, therefore can save system resource;
2, prior art is issued primary and backup machine agency with broadcast mode with the database manipulation bag and is finished data Replica, has increased the weight of system's distribution load, has prolonged system's treatment scheme, causes easily the waste of system overhead, affects the concurrent efficient of system; And the present invention is according to the call request building database of operation layer and being connected of operation layer, and to realize operation layer to the operation of database, therefore, the present invention can avoid system overhead waste and the concurrent inefficient problem that broadcast mode brings in the prior art;
3, prior art utilizes message authentication mechanism to carry out the active and standby switching of Database Systems, causes easily in certain timing time the message queuing of blocking up, and a large amount of requests waits can be caused in the request peak period, have reduced the treatment effeciency of system; And the present invention is by to set up available flag be available database instance correspondence database and being connected of described operation layer, realize master-slave database efficient, switch in real time, can avoid repeatedly network overhead that message authentication brings and a large amount of stand-by period;
In a word, the present invention can guaranteeing to reduce to greatest extent network and system overhead under the normal fault-tolerant condition, improve the concurrent ability of system.
Above-mentioned explanation only is the general introduction of technical solution of the present invention, for can clearer understanding technological means of the present invention, and can be implemented according to the content of instructions, and for above and other objects of the present invention, feature and advantage can be become apparent, below especially exemplified by the specific embodiment of the present invention.
Description of drawings
By reading hereinafter detailed description of the preferred embodiment, various other advantage and benefits will become cheer and bright for those of ordinary skills.Accompanying drawing only is used for the purpose of preferred implementation is shown, and does not think limitation of the present invention.And in whole accompanying drawing, represent identical parts with identical reference symbol.In the accompanying drawings:
Fig. 1 shows the according to an embodiment of the invention changing method process flow diagram of database;
Fig. 2 shows the according to an embodiment of the invention structural drawing of transaction processing system;
Fig. 3 shows the according to an embodiment of the invention changing method process flow diagram of database;
Fig. 4 shows the according to an embodiment of the invention changing method process flow diagram of database;
Fig. 5 shows the according to an embodiment of the invention changing method process flow diagram of database;
Fig. 6 shows and partly copies synchronously according to an embodiment of the invention process flow diagram; And
Fig. 7 shows the according to an embodiment of the invention switching device shifter structural drawing of database.
Embodiment
Exemplary embodiment of the present disclosure is described below with reference to accompanying drawings in more detail.Although shown exemplary embodiment of the present disclosure in the accompanying drawing, yet should be appreciated that and to realize the disclosure and the embodiment that should do not set forth limits here with various forms.On the contrary, it is in order to understand the disclosure more thoroughly that these embodiment are provided, and can with the scope of the present disclosure complete convey to those skilled in the art.
With reference to Fig. 1, show the according to an embodiment of the invention changing method process flow diagram of database, specifically can comprise:
The database instance of step 101, employing associative container stores service, the available flag of database instance when storage is available in the described associative container;
Service is simply introduced it at this for the known technology in the database field.Service is generally used for realizing function in the operation system, and service specifically can comprise database instance and database.Wherein, database instance just refers to be in the calculator memory database program of running status, and is some memory headrooms of these programme distributions; Database instance is arranged in internal memory, only just exists when database is in running status; Database instance be responsible for realizing network connection to the user is provided, the various functions of the file etc. that reads and writes data.Database is exactly the file (data file, journal file, control documents etc.) on the actual disk, is responsible for save data.Usually, the corresponding database of database instance, but and the data of this database instance operational correspondence database, a database may corresponding one or more database instances.Service, database instance and database all have unique title, are respectively Service name, database instance name and database name.
In an embodiment of the present invention, can obtain as follows the database instance of the service of storing in the described associative container:
Step S101, when service starts, obtain the database instance of service according to the operating system environment variable;
The operating system environment variable is used for operating system mutual, also, will expect the database instance name in operating system, should use the operating system environment variable; The operating system environment variable is normally used for the title of definition database Parameter File, and parameter file of database includes ordered series of numbers and database configuration information, just comprises the information of whole master-slave databases of service in the database configuration information wherein.
Like this, when service started, the information that parameter file of database namely can read whole master-slave databases of service was opened in the path that can obtain by the operating system environment variable parameter file of database, and then the database instance that can obtain serving.
Step S102, employing database connection pool are deposited fetched data storehouse example and corresponding the connection;
Database connects the resource of the limited costliness that is a kind of key, and this point embodies particularly outstandingly in multi-user's Web page application program.The management that database is connected can significantly impact retractility and the robustness of whole application program, has influence on the performance index of program.Database connection pool puts forward for this problem just.Database connection pool is responsible for distributing, manages and is connected database and connects, and its allows application program to reuse an existing database connection, and or else is to rebulid one; The database that the releasing idling time surpasses maximum idle time connects to avoid because do not discharge that database connects the database that causes to connect to omit.This technology can obviously improve the performance to database manipulation.
Step S103, for connecting normal database instance in the described database connection pool, its available flag is set to available, and insert in the corresponding associative container.
In the embodiment of the invention, can be for concerning one to one between database instance and the database; The connection of database instance can be used for representing serving being connected of place server and database instance correspondence database, connects normally still unusually can judge according to the rreturn value of service place server.
In actual applications, can detect whether each database instance connects normally in the Data Connection Pool, if connect unusually, think that then principal and subordinate's library initialization is wrong, service is withdrawed from; If connect normal then the database instance in the connection pool is inserted in the corresponding associative container, and be set to its available flag available.
Associative container of the present invention is similar to a kind of correlation database in the internal memory in idea: every data have a key assignments (key) and an actual value (value) in the associative container.When element was inserted into associative container, internal mechanism can according to key assignments, place specific position according to certain rule with element.Associative container does not have so-called concept (only having greatest member, least member) end to end.
The STL(Standard Template Library of standard, STL) associative container can be divided into set and map two large classes, and redundant organism multiset and the multimap of these two large classes.Those skilled in the art can adopt wherein arbitrary according to actual needs, and the present invention is not limited concrete associative container.
Step 102, when receiving the call request of operation layer, set up being connected of master data base and described operation layer;
In the embodiment of the invention, database manipulation layer and operation layer are peeled off, and particularly, the database manipulation layer can carry out database manipulation according to the call request of operation layer, with the service request of the layer of managing business.
With reference to Fig. 2, show the according to an embodiment of the invention structural drawing of transaction processing system, specifically can comprise client 201, gateway system 202, account system service end 203, business service end 204, operation layer 205, database manipulation layer 206, database manipulation layer 206 further comprises master data base 261 and from database 262.
The flow process of the transaction processing system shown in Figure 2 request of managing business is as follows:
Step S201, when receiving the payment request that the user initiates from the page, client 201 should be paid and ask to throw to gateway system 202;
Step S202, gateway system 202 should be paid request and be transmitted to account system service end 203 after obtaining the payment path;
Step S203, account system service end 203 forward it to concrete business service end 204 according to the service parameter of this payment request;
Step S204, business service end 204 should be paid request and deliver to operation layer 205;
Step S205,205 pairs of this payment requests of operation layer are processed, when needs operate database, and calling data storehouse operation layer 206.
In the embodiment of the invention, when receiving the call request of operation layer, master data base 261 and described operation layer 205 is connected in the acquiescence building database operation layer 206.
Step 103, to choose available flag from described associative container be available database instance;
In the embodiment of the invention, associative container can be used for the database instance of stores service, the available flag of database instance when storage is available in the described associative container, and like this, the available flag of all database instances when service starts is available in the described associative container.
But the available flag of database instance is not unalterable in the described associative container, because the connection of database corresponding to database instance may be broken down, modal fault is to connect fault.Therefore, the present invention uses certain connection fault condition as the condition of upgrading available flag.
Following step 105 has been described to use and has been connected the process that fault condition upgrades available flag; Wherein, connect fault condition and can be database and unusual number of times of being connected of described operation layer, but acquisition database is unusual with being connected of described operation layer in specific implementation, and adopt counter records database and unusual number of times of being connected of described operation layer; Described first threshold can be determined according to actual demand by those skilled in the art, and for example, an example of first threshold is 3 etc.
In a kind of application example of the present invention, described step 103 is chosen available flag from described associative container be that the implementation procedure of available database instance can comprise:
First database instance is current example in step S301, the described associative container of initial default;
If the available flag of step S302, the current example of detection available, is then chosen successfully and execution in step 104, if unavailable, execution in step S303;
Step S303, check the linking number of current usefulness, if linking number is not 0, execution in step C4 then is if linking number is 0 then execution in step S305;
Step S304, think that current database is unavailable, return sky;
Step S305, obtain the index that available flag in the database connection pool is available database instance, if obtain the result for empty, execution in step S306 then, if obtain the result for empty, execution in step S307 then;
Step S306, warning are withdrawed from;
Step S307, to choose an available flag from obtain the result be available database instance, and execution in step 104.
Need to prove that warning of the present invention can be used for sending prompting to the data base administrator, carried out the maintenance of database by the keeper.
Step 104, set up being connected of selected database instance correspondence database and described operation layer;
Step 105, when capturing database unusual number of times be greater than first threshold with being connected of described operation layer, be revised as the available flag of associated databases example in the described associative container unavailable.
The present invention is when receiving the call request of operation layer, acquiescence is set up being connected of master data base and described operation layer, and, if the available flag of master data base correspondence database example is unavailable, then set up being connected of availability database example correspondence database and described operation layer; As seen, the present invention is by to set up available flag be available database instance correspondence database and being connected of described operation layer, realize master-slave database efficient, switch in real time.
With respect to prior art, the embodiment of the invention has following advantage:
1, active and standby machine respectively has oneself agency in the prior art, and practical function is similar, causes easily system redundancy and the wasting of resources; And the present invention carries out unified agent to all database instances of serving, and like this, peel off in database broker of the present invention and principal and subordinate storehouse, can form public database broker, therefore can save system resource;
2, prior art is issued primary and backup machine agency with broadcast mode with the database manipulation bag and is finished data Replica, has increased the weight of system's distribution load, has prolonged system's treatment scheme, causes easily the waste of system overhead, affects the concurrent efficient of system; The present invention is according to the call request building database of operation layer and being connected of operation layer, and to realize operation layer to the operation of database, therefore, the present invention can avoid system overhead waste and the concurrent inefficient problem that broadcast mode brings in the prior art;
3, prior art utilizes message authentication mechanism to carry out the active and standby switching of Database Systems, causes easily in certain timing time the message queuing of blocking up, and a large amount of requests waits can be caused in the request peak period, have reduced the treatment effeciency of system; And the present invention is by to set up available flag be available database instance correspondence database and being connected of described operation layer, realize master-slave database efficient, switch in real time, can avoid repeatedly network overhead that message authentication brings and a large amount of stand-by period;
To sum up, the present invention can guaranteeing to reduce to greatest extent network and system overhead under the normal fault-tolerant condition, improve the concurrent ability of system.
With reference to Fig. 3, show the according to an embodiment of the invention changing method process flow diagram of database, specifically can comprise:
The database instance of step 301, employing associative container stores service, the available flag of database instance when storage is available in the described associative container;
Step 302, when receiving the call request of operation layer, set up being connected of master data base and described operation layer;
Step 303, to choose available flag from described associative container be available database instance;
Step 304, set up being connected of selected database instance correspondence database and described operation layer;
Step 305, when capturing database unusual number of times be greater than first threshold with being connected of described operation layer, be revised as the available flag of associated databases example in the described associative container unavailable;
Whether the available flag that step 306, infinite loop are surveyed database instance in the described associative container is available, if unavailable, then send alarm, be that database corresponding to disabled database instance safeguard according to described alarm to described available flag by the data base administrator, and after maintenance is finished, in the look-up table of database, be set to the available flag of described database available;
Described look-up table is corresponding one by one with database, is suitable for the available flag of stored data base;
Step 307, be disabled database instance for described available flag, but the available flag of database it is the time spent in detecting the look-up table of its correspondence database, is revised as its available flag available in described associative container.
In specific implementation, can start the available flag that a special thread infinite loop is surveyed database instance in the described associative container.In addition, be the mitigation system load, the cycle N that described infinite loop is surveyed can be set, such as 1s, 2s etc., one is exemplified as and can passing through slepp(N after each the detection) etc. function make the computer system dormancy; Certainly, the present invention is not limited the mode of the concrete cycle N that described infinite loop detection is set.
Alarm of the present invention can be used for sending prompting to the data base administrator, is carried out the maintenance of database by the keeper; Further, the present invention can adopt the available flag of look-up table stored data base, this look-up table can be operated by the data base administrator, for example, the data base administrator can be after receiving alarm, in the look-up table of associated databases, the available flag of described database is set to unavailable, and after maintenance is finished, in the look-up table of database, the available flag of described database is set to available, etc.
In addition, the embodiment of the invention is disabled database instance for described available flag, can detect the available flag of database in the look-up table of correspondence database, but and be the time spent in testing result, in described associative container, be revised as its available flag available.
With reference to Fig. 4, show the according to an embodiment of the invention changing method process flow diagram of database, specifically can comprise:
The database instance of step 401, employing associative container stores service, the available flag of database instance when storage is available in the described associative container;
Step 402, when receiving the call request of operation layer, set up being connected of master data base and described operation layer;
Step 403, to choose available flag from described associative container be available database instance;
Step 404, for database, record the number that it is connected with described operation layer;
Step 405, whether judge number that selected database instance correspondence database is connected with described operation layer greater than Second Threshold, if, then send alarm, otherwise, being connected of described database and described operation layer set up;
Step 406, when capturing database unusual number of times be greater than first threshold with being connected of described operation layer, be revised as the available flag of associated databases example in the described associative container unavailable.
Database has performance bottleneck usually, if do not limit carry out the multitype database operation at database, in the reaction time of then reducing easily database, affect the handling property of operation layer.
Reach performance bottleneck for fear of database, the Second Threshold of present embodiment is used for the critical value of the number that the expression database is connected with operation layer, greater than Second Threshold then database probably reach performance bottleneck, so send alarm.In practice, Second Threshold can be drawn according to the actual requirements by those skilled in the art, and for example, the data base administrator can obtain Second Threshold etc. by test, and the present invention is not limited the concrete method that Second Threshold is set.
With reference to Fig. 5, show the according to an embodiment of the invention changing method process flow diagram of database, specifically can comprise:
The database instance of step 501, employing associative container stores service, the available flag of database instance when storage is available in the described associative container;
Step 502, when receiving the call request of operation layer, set up being connected of master data base and described operation layer;
Step 503, to choose available flag from described associative container be available database instance;
Step 504, set up being connected of selected database instance correspondence database and described operation layer;
Step 505, when capturing database unusual number of times be greater than first threshold with being connected of described operation layer, be revised as the available flag of associated databases example in the described associative container unavailable;
Step 506, carry out in the processing procedure of current affairs in described operation layer institute connection data storehouse, with described operation layer institute connection data storehouse as master data base, with the renewal data Replica of described master data base to from database;
Step 507, wait for a plurality ofly after at least one copies successfully from database in described master data base, carry out the processing of next affairs.
Leader follower replication of the prior art is asynchronous replication, asynchronous replication can provide best performance, because master data base is after the data that will upgrade write in its binary log (Binlog) file, the renewal data to be verified such as need not and whether copied at least one from database, just can freely process other affairs.Although asynchronous replication has the fast advantage of processing speed, also has very high risk: if master data base moment breaks down, and from the database copy data that is not able to do in time, can cause the inconsistent of master data base/from database data, even cause loss of data.Here, affairs also are db transaction (Database Transaction), refer to the sequence of operations of carrying out as single logical unit of work.
Risk for asynchronous replication, the present invention adopts and partly copies synchronously the renewal data Replica of described master data base to from database, in the implementation process that partly copies synchronously, waiting for a plurality ofly after at least one copies successfully from database, master data base can be carried out the processing of next affairs; Therefore, can guarantee that master data base and at least one are from the data consistency between the database and redundancy.
With reference to Fig. 6, show and partly copy synchronously according to an embodiment of the invention process flow diagram, wherein, master data base and half synchronous reproducer all is installed from the database; Master data base waits for that a plurality of at least one copies successfully from database after the more new data with application program writes in its binary log file, do not carry out the processing of next affairs in waiting process; New data writes behind the relaying binary log file of database inciting somebody to action more, can return acknowledge message to master data base from database, and described acknowledge message representative copies successfully.
Certainly, master data base can not be waited for from the database replication success always, because just in case hang from database, master data base will be in waiting status and can not processing transactions always so.
Therefore, in a preferred embodiment of the present invention, can define a time-out time threshold value, prevent that the stand-by period is oversize, the common ms of unit; If surpass the time-out time threshold value, from also not response of database, then can switch to the asynchronous replication pattern from half synchronous replication mode.Correspondingly, described method can also comprise: in stand-by period during greater than the time-out time threshold value, a plurality of at least one copies successful wait from database for described to stop described master data base, and carries out the processing of next affairs.
With reference to Fig. 7, show the according to an embodiment of the invention structural drawing of the switching device shifter of database, specifically can comprise:
Associative container 701 is suitable for the database instance of stores service, and the available flag of database instance when storage is available in the described associative container;
First connects and to set up module 702, is suitable for when receiving the call request of operation layer, sets up being connected of master data base and described operation layer;
Example is chosen module 703, and being suitable for choosing from described associative container available flag is available database instance;
Second connects and to set up module 704, is suitable for setting up being connected of selected database instance correspondence database and described operation layer; And
Sign modified module 705 is suitable for when capturing database unusual number of times is greater than first threshold with being connected of described operation layer, is revised as the available flag of associated databases example in the described associative container unavailable.
In a preferred embodiment of the present invention, described device can also comprise:
The loop detection module, whether the available flag that is suitable for database instance in the described associative container of loop detection is available;
The first warning reminding module, when the available flag that is suitable for database instance in detecting described associative container is unavailable, send alarm, be that database corresponding to disabled database instance safeguard according to described alarm to described available flag by the data base administrator, and after maintenance is finished, in the look-up table of database, be set to the available flag of described database available; Described look-up table is corresponding one by one with database, is suitable for the available flag of stored data base;
Look-up table detects modified module, and being suitable for for described available flag is disabled database instance, but the available flag of database is the time spent in detecting the look-up table of its correspondence database, is revised as its available flag available in described associative container.
In another kind of preferred embodiment of the present invention, described device can also comprise:
The linking number logging modle is suitable for for database, records the number that it is connected with described operation layer;
The linking number judge module, be suitable for described second connect set up module and set up being connected of selected database instance correspondence database and described operation layer before, judge that whether number that described database is connected with described operation layer is greater than Second Threshold;
The second warning reminding module when being suitable for the number that is connected with described operation layer at described database greater than Second Threshold, sends alarm;
Described second connects and to set up module, when also specifically being suitable for the number that is connected with described operation layer at described database less than or equal to Second Threshold, sets up being connected of described database and described operation layer.
In another preferred embodiment of the present invention, described device can also comprise:
The leader follower replication module is suitable for carrying out in the processing procedure of current affairs in described operation layer institute connection data storehouse, with described operation layer institute connection data storehouse as master data base, with the renewal data Replica of described master data base to from database;
Wait for module, be suitable for waiting in described master data base a plurality of after at least one copies successfully from database, carry out the processing of next affairs.
In embodiments of the present invention, preferably, described device can also comprise:
Wait for stopping modular, be suitable in stand-by period during greater than the time-out time threshold value that a plurality of at least one copies successful wait from database for described to stop described master data base, and carries out the processing of next affairs.
In a preferred embodiment of the present invention, described device can also comprise: the container instance acquisition module that is suitable for obtaining the database instance of the service of storing in the described associative container;
Described container instance acquisition module specifically can comprise:
Service Instance obtains submodule, is suitable for obtaining the database instance of service according to the operating system environment variable when service starts;
Database connection pool is suitable for depositing fetched data storehouse example and corresponding the connection;
The intron module is suitable for connecting normal database instance in the described database connection pool, its available flag is set to available, and inserts in the corresponding associative container.
Intrinsic not relevant with any certain computer, virtual system or miscellaneous equipment with demonstration at this algorithm that provides.Various general-purpose systems also can be with using based on the teaching at this.According to top description, it is apparent constructing the desired structure of this type systematic.In addition, the present invention is not also for any certain programmed language.Should be understood that and to utilize various programming languages to realize content of the present invention described here, and the top description that language-specific is done is in order to disclose preferred forms of the present invention.
In the instructions that provides herein, a large amount of details have been described.Yet, can understand, embodiments of the invention can be put into practice in the situation of these details not having.In some instances, be not shown specifically known method, structure and technology, so that not fuzzy understanding of this description.
Similarly, be to be understood that, in order to simplify the disclosure and to help to understand one or more in each inventive aspect, in the description to exemplary embodiment of the present invention, each feature of the present invention is grouped together in single embodiment, figure or the description to it sometimes in the above.Yet the method for the disclosure should be construed to the following intention of reflection: namely the present invention for required protection requires the more feature of feature clearly put down in writing than institute in each claim.Or rather, as following claims reflected, inventive aspect was to be less than all features of the disclosed single embodiment in front.Therefore, follow claims of embodiment and incorporate clearly thus this embodiment into, wherein each claim itself is as independent embodiment of the present invention.
Those skilled in the art are appreciated that and can adaptively change and they are arranged in one or more equipment different from this embodiment the module in the equipment among the embodiment.Can be combined into a module or unit or assembly to the module among the embodiment or unit or assembly, and can be divided into a plurality of submodules or subelement or sub-component to them in addition.In such feature and/or process or unit at least some are mutually repelling, and can adopt any combination to disclosed all features in this instructions (comprising claim, summary and the accompanying drawing followed) and so all processes or the unit of disclosed any method or equipment make up.Unless in addition clearly statement, disclosed each feature can be by providing identical, being equal to or the alternative features of similar purpose replaces in this instructions (comprising claim, summary and the accompanying drawing followed).
In addition, those skilled in the art can understand, although embodiment more described herein comprise some feature rather than further feature included among other embodiment, the combination of the feature of different embodiment means and is within the scope of the present invention and forms different embodiment.For example, in the following claims, the one of any of embodiment required for protection can be used with array mode arbitrarily.
All parts embodiment of the present invention can realize with hardware, perhaps realizes with the software module of moving at one or more processor, and perhaps the combination with them realizes.It will be understood by those of skill in the art that and to use in practice microprocessor or digital signal processor (DSP) to realize according to some or all some or repertoire of parts in the embodiment of the invention.The present invention can also be embodied as part or all equipment or the device program (for example, computer program and computer program) that is suitable for carrying out method as described herein.Such realization program of the present invention can be stored on the computer-readable medium, perhaps can have the form of one or more signal.Such signal can be downloaded from internet website and obtain, and perhaps provides at carrier signal, perhaps provides with any other form.
It should be noted above-described embodiment the present invention will be described rather than limit the invention, and those skilled in the art can design alternative embodiment in the situation of the scope that does not break away from claims.In the claims, any reference symbol between bracket should be configured to limitations on claims.Word " comprises " not to be got rid of existence and is not listed in element or step in the claim.Being positioned at word " " before the element or " one " does not get rid of and has a plurality of such elements.The present invention can realize by means of the hardware that includes some different elements and by means of the computing machine of suitably programming.In having enumerated the unit claim of some devices, several in these devices can be to come imbody by same hardware branch.The use of word first, second and C grade does not represent any order.Can be title with these word explanations.

Claims (12)

1. the changing method of a database comprises:
Adopt the database instance of associative container stores service, the available flag of database instance when storage is available in the described associative container;
When receiving the call request of operation layer, set up being connected of master data base and described operation layer;
Choosing available flag from described associative container is available database instance;
Set up being connected of selected database instance correspondence database and described operation layer;
When capturing database unusual number of times is greater than first threshold with being connected of described operation layer, be revised as the available flag of associated databases example in the described associative container unavailable.
2. the method for claim 1 also comprises:
Whether the available flag that infinite loop is surveyed database instance in the described associative container is available, if unavailable, then send alarm, be that database corresponding to disabled database instance safeguard according to described alarm to described available flag by the data base administrator, and after maintenance is finished, in the look-up table of database, be set to the available flag of described database available; Described look-up table is corresponding one by one with database, is suitable for the available flag of stored data base;
Be disabled database instance for described available flag, but the available flag of database it is the time spent in detecting the look-up table of its correspondence database, is revised as its available flag available in described associative container.
3. the method for claim 1 also comprises:
For database, record the number that it is connected with described operation layer;
Before setting up being connected of selected database instance correspondence database and described operation layer, judge that whether number that described database is connected with described operation layer is greater than Second Threshold, if then send alarm, otherwise, set up being connected of described database and described operation layer.
4. the method for claim 1 also comprises:
Carry out in the processing procedure of current affairs in described operation layer institute connection data storehouse, with described operation layer institute connection data storehouse as master data base, with the renewal data Replica of described master data base to from database;
Wait for a plurality ofly after at least one copies successfully from database in described master data base, carry out the processing of next affairs.
5. method as claimed in claim 4 also comprises:
In stand-by period during greater than the time-out time threshold value, a plurality of at least one copies successful wait from database for described to stop described master data base, and carries out the processing of next affairs.
6. the method for claim 1, obtain as follows the database instance of the service of storing in the described associative container:
When service starts, obtain the database instance of service according to the operating system environment variable;
Adopt database connection pool to deposit fetched data storehouse example and corresponding the connection;
For connecting normal database instance in the described database connection pool, its available flag is set to available, and insert in the corresponding associative container.
7. the switching device shifter of a database comprises:
Associative container is suitable for the database instance of stores service, and the available flag of database instance when storage is available in the described associative container;
First connects and to set up module, is suitable for when receiving the call request of operation layer, sets up being connected of master data base and described operation layer;
Example is chosen module, and being suitable for choosing from described associative container available flag is available database instance;
Second connects and to set up module, is suitable for setting up being connected of selected database instance correspondence database and described operation layer; And
The sign modified module is suitable for when capturing database unusual number of times is greater than first threshold with being connected of described operation layer, is revised as the available flag of associated databases example in the described associative container unavailable.
8. device as claimed in claim 7 also comprises:
The loop detection module, whether the available flag that is suitable for database instance in the described associative container of loop detection is available;
The first warning reminding module, when the available flag that is suitable for database instance in detecting described associative container is unavailable, send alarm, be that database corresponding to disabled database instance safeguard according to described alarm to described available flag by the data base administrator, and after maintenance is finished, in the look-up table of database, be set to the available flag of described database available; Described look-up table is corresponding one by one with database, is suitable for the available flag of stored data base;
Look-up table detects modified module, and being suitable for for described available flag is disabled database instance, but the available flag of database is the time spent in detecting the look-up table of its correspondence database, is revised as its available flag available in described associative container.
9. device as claimed in claim 7 also comprises:
The linking number logging modle is suitable for for database, records the number that it is connected with described operation layer;
The linking number judge module, be suitable for described second connect set up module and set up being connected of selected database instance correspondence database and described operation layer before, judge that whether number that described database is connected with described operation layer is greater than Second Threshold;
The second warning reminding module when being suitable for the number that is connected with described operation layer at described database greater than Second Threshold, sends alarm;
Described second connects and to set up module, when also specifically being suitable for the number that is connected with described operation layer at described database less than or equal to Second Threshold, sets up being connected of described database and described operation layer.
10. device as claimed in claim 7 also comprises:
The leader follower replication module is suitable for carrying out in the processing procedure of current affairs in described operation layer institute connection data storehouse, with described operation layer institute connection data storehouse as master data base, with the renewal data Replica of described master data base to from database;
Wait for module, be suitable for waiting in described master data base a plurality of after at least one copies successfully from database, carry out the processing of next affairs.
11. device as claimed in claim 10 also comprises:
Wait for stopping modular, be suitable in stand-by period during greater than the time-out time threshold value that a plurality of at least one copies successful wait from database for described to stop described master data base, and carries out the processing of next affairs.
12. device as claimed in claim 7 also comprises: the container instance acquisition module that is suitable for obtaining the database instance of the service of storing in the described associative container;
Described container instance acquisition module comprises:
Service Instance obtains submodule, is suitable for obtaining the database instance of service according to the operating system environment variable when service starts;
Database connection pool is suitable for depositing fetched data storehouse example and corresponding the connection;
The intron module is suitable for connecting normal database instance in the described database connection pool, its available flag is set to available, and inserts in the corresponding associative container.
CN201210425127.9A 2012-10-30 2012-10-30 A kind of switching method and apparatus of database Active CN102955851B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210425127.9A CN102955851B (en) 2012-10-30 2012-10-30 A kind of switching method and apparatus of database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210425127.9A CN102955851B (en) 2012-10-30 2012-10-30 A kind of switching method and apparatus of database

Publications (2)

Publication Number Publication Date
CN102955851A true CN102955851A (en) 2013-03-06
CN102955851B CN102955851B (en) 2016-05-11

Family

ID=47764657

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210425127.9A Active CN102955851B (en) 2012-10-30 2012-10-30 A kind of switching method and apparatus of database

Country Status (1)

Country Link
CN (1) CN102955851B (en)

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104252505A (en) * 2013-06-29 2014-12-31 北京新媒传信科技有限公司 Method and device for synchronizing database instance in database management platform
CN105183874A (en) * 2015-09-19 2015-12-23 北京暴风科技股份有限公司 Self-maintenance distributed database agent method
CN105468619A (en) * 2014-09-03 2016-04-06 阿里巴巴集团控股有限公司 Resource distribution method and device used for database connection pool
CN105574026A (en) * 2014-10-15 2016-05-11 腾讯科技(深圳)有限公司 Method and device for service supporting by using non-relational database
CN105975579A (en) * 2016-05-05 2016-09-28 北京思特奇信息技术股份有限公司 Primary and backup copying method of memory database and memory database system
CN106156076A (en) * 2015-03-31 2016-11-23 阿里巴巴集团控股有限公司 The method and system that data process
CN107004010A (en) * 2014-12-08 2017-08-01 国际商业机器公司 Control multidatabase system
WO2017177941A1 (en) * 2016-04-13 2017-10-19 中兴通讯股份有限公司 Active/standby database switching method and apparatus
CN107368485A (en) * 2016-05-12 2017-11-21 苏宁云商集团股份有限公司 The management method and Database Systems of a kind of database
CN108804463A (en) * 2017-05-03 2018-11-13 杭州海康威视数字技术股份有限公司 A kind of method of data synchronization of MySQL database, device and electronic equipment
CN109117432A (en) * 2017-06-22 2019-01-01 北京京东尚科信息技术有限公司 A kind of method and device obtaining data
CN109491830A (en) * 2017-09-12 2019-03-19 北京京东尚科信息技术有限公司 The method and system in switch data source
CN110347658A (en) * 2019-06-11 2019-10-18 无线生活(杭州)信息科技有限公司 Database instance switching method and device
CN110377664A (en) * 2019-07-22 2019-10-25 腾讯科技(深圳)有限公司 Method of data synchronization, device, server and storage medium
CN112685390A (en) * 2021-03-22 2021-04-20 阿里云计算有限公司 Database instance management method and device and computing equipment

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101408899B (en) * 2008-11-21 2010-09-29 北京中企开源信息技术有限公司 Method and apparatus for switching website multiple data sources
CN101854373B (en) * 2009-04-01 2013-10-09 华为技术有限公司 Target switching method, server node and colony system
CN101980207B (en) * 2010-11-09 2012-05-30 中国电信股份有限公司 Method and system for implementing database access
CN102194009B (en) * 2011-06-09 2013-06-05 北京新媒传信科技有限公司 Database hosting method and database hosting platform system

Cited By (22)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104252505A (en) * 2013-06-29 2014-12-31 北京新媒传信科技有限公司 Method and device for synchronizing database instance in database management platform
CN104252505B (en) * 2013-06-29 2017-08-04 北京新媒传信科技有限公司 The synchronous method and device of database instance in database management platform
CN105468619B (en) * 2014-09-03 2019-10-29 阿里巴巴集团控股有限公司 Resource allocation methods and device for database connection pool
CN105468619A (en) * 2014-09-03 2016-04-06 阿里巴巴集团控股有限公司 Resource distribution method and device used for database connection pool
CN105574026A (en) * 2014-10-15 2016-05-11 腾讯科技(深圳)有限公司 Method and device for service supporting by using non-relational database
CN107004010A (en) * 2014-12-08 2017-08-01 国际商业机器公司 Control multidatabase system
US11176171B2 (en) 2014-12-08 2021-11-16 International Business Machines Corporation Controlling a multi-database system
CN107004010B (en) * 2014-12-08 2020-08-11 国际商业机器公司 Controlling multiple database systems
US10552451B2 (en) 2014-12-08 2020-02-04 International Business Machines Corporation Controlling a multi-database system
CN106156076A (en) * 2015-03-31 2016-11-23 阿里巴巴集团控股有限公司 The method and system that data process
CN105183874A (en) * 2015-09-19 2015-12-23 北京暴风科技股份有限公司 Self-maintenance distributed database agent method
WO2017177941A1 (en) * 2016-04-13 2017-10-19 中兴通讯股份有限公司 Active/standby database switching method and apparatus
CN105975579A (en) * 2016-05-05 2016-09-28 北京思特奇信息技术股份有限公司 Primary and backup copying method of memory database and memory database system
CN105975579B (en) * 2016-05-05 2019-09-17 北京思特奇信息技术股份有限公司 A kind of active and standby clone method and memory database system of memory database
CN107368485A (en) * 2016-05-12 2017-11-21 苏宁云商集团股份有限公司 The management method and Database Systems of a kind of database
CN108804463A (en) * 2017-05-03 2018-11-13 杭州海康威视数字技术股份有限公司 A kind of method of data synchronization of MySQL database, device and electronic equipment
CN109117432A (en) * 2017-06-22 2019-01-01 北京京东尚科信息技术有限公司 A kind of method and device obtaining data
CN109491830A (en) * 2017-09-12 2019-03-19 北京京东尚科信息技术有限公司 The method and system in switch data source
CN110347658A (en) * 2019-06-11 2019-10-18 无线生活(杭州)信息科技有限公司 Database instance switching method and device
CN110377664A (en) * 2019-07-22 2019-10-25 腾讯科技(深圳)有限公司 Method of data synchronization, device, server and storage medium
CN112685390A (en) * 2021-03-22 2021-04-20 阿里云计算有限公司 Database instance management method and device and computing equipment
CN112685390B (en) * 2021-03-22 2021-12-21 阿里云计算有限公司 Database instance management method and device and computing equipment

Also Published As

Publication number Publication date
CN102955851B (en) 2016-05-11

Similar Documents

Publication Publication Date Title
CN102955851A (en) Database switching method and device
CN102968457B (en) Database method for switching between and system
JP5102901B2 (en) Method and system for maintaining data integrity between multiple data servers across a data center
Hammer et al. Reliability mechanisms for SDD-1: A system for distributed databases
US8495635B2 (en) Mechanism to enable and ensure failover integrity and high availability of batch processing
US8868601B2 (en) Distributed file system logging
US8843581B2 (en) Live object pattern for use with a distributed cache
EP0444376A1 (en) Mechanism for passing messages between several processors coupled through a shared intelligent memory
CN101997823A (en) Distributed file system and data access method thereof
CN102893256A (en) Handling operating system (os) transitions in an unbounded transactional memory (utm) mode
CN103761141A (en) Method and device for realizing message queue
CN103414712A (en) Management system and method of distributed virtual desktop
US20080115128A1 (en) Method, system and computer program product for implementing shadow queues for recovery of messages
CN103412822A (en) Operation method of non-volatile RAM, data operation method and relevant device
CN104503863A (en) Kernel mode and user mode data exchange method used for virtual container system disaster recovery
CN104407945A (en) Data backup method, data backup device and data backup system
CN105162879A (en) Method, device and system for realizing data consistency among plurality of machine rooms
KR20150083938A (en) System for interoperation between dds and dbms
CN106777394A (en) A kind of cluster file system
CN110162344A (en) A kind of method, apparatus, computer equipment and readable storage medium storing program for executing that current limliting is isolated
CN101176068B (en) Apparatus, system, and method for facilitating communication between an enterprise information system and a client
EP4086758A1 (en) Software update on legacy system without application disruption
WO2018234265A1 (en) System and apparatus for a guaranteed exactly once processing of an event in a distributed event-driven environment
CN113767372A (en) Executing multiple data requests of a multi-core processor
JP2008310591A (en) Cluster system, computer, and failure recovery method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park)

Patentee after: BEIJING QIHOO TECHNOLOGY Co.,Ltd.

Patentee after: Beijing Qizhi Business Consulting Co.,Ltd.

Address before: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park)

Patentee before: BEIJING QIHOO TECHNOLOGY Co.,Ltd.

Patentee before: Qizhi software (Beijing) Co.,Ltd.

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20240115

Address after: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park)

Patentee after: BEIJING QIHOO TECHNOLOGY Co.,Ltd.

Address before: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park)

Patentee before: BEIJING QIHOO TECHNOLOGY Co.,Ltd.

Patentee before: Beijing Qizhi Business Consulting Co.,Ltd.