CN107291787A - Master/slave data storehouse switching method and apparatus - Google Patents

Master/slave data storehouse switching method and apparatus Download PDF

Info

Publication number
CN107291787A
CN107291787A CN201610230656.1A CN201610230656A CN107291787A CN 107291787 A CN107291787 A CN 107291787A CN 201610230656 A CN201610230656 A CN 201610230656A CN 107291787 A CN107291787 A CN 107291787A
Authority
CN
China
Prior art keywords
database
standby
native
current location
client
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
CN201610230656.1A
Other languages
Chinese (zh)
Other versions
CN107291787B (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.)
ZTE Corp
China Citic Bank Corp Ltd
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CN201610230656.1A priority Critical patent/CN107291787B/en
Priority to PCT/CN2017/080418 priority patent/WO2017177941A1/en
Publication of CN107291787A publication Critical patent/CN107291787A/en
Application granted granted Critical
Publication of CN107291787B publication Critical patent/CN107291787B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a kind of master/slave data storehouse switching method and apparatus, its method includes:Perform connection native database service operations;Receive to client database transmission to client database current location;If the frequency of failure for connecting database service operation exceedes default number of times, then judge that native database is abnormal, and perform alarm operation or native database and between client database carry out active-standby switch operation, or, default number of times is exceeded to the frequency of failure to client database current location that client database is sent if receiving, alarm operation is performed or in native database and to carrying out active-standby switch operation between client database.When the present invention solves that master/slave data storehouse is switched in the prior art, data precision is poor, complex operation, the problem of stability is low.Realize monitoring in real time and grasp master/slave data storehouse synchronization discrepancy away from situation, simplify operation, it is ensured that data consistency, while avoid switching by mistake.

Description

Master/slave data storehouse switching method and apparatus
Technical field
The present invention relates to database technical field, more particularly to a kind of master/slave data storehouse switching method and apparatus.
Background technology
In being applied in present-day data storehouse, database concurrency degree is high, data growth rate is current data bank service soon Two major features.In a short time, it is understood that there may be mass data is newly-increased or changes.As data bulk level is incremented by, From byte, kilobytes, Mbytes till now ten thousand Mbytes, it is good with reference to MariaDB/MySQL databases Characteristic extending transversely, the distributed data base based on MariaDB/MySQL databases is widely used.
Simultaneously in order to improve database disaster tolerance, each database provider proposes corresponding strategy, wherein MariaDB/MySQL databases use leader follower replication strategy, and its core concept is that primary database is externally carried For service, when master library has renewal, the SQL for updating operation can be write binary log (Bin log) by master library, And the index of a binary log file is safeguarded, in order to journal file samsara (Rotate).Read from database Take primary database operation to generate binlog daily records, and perform relevant action in binlog daily records, so as to ensure principal and subordinate Database data is consistent.When the machine of delaying occurs in database host, it is necessary to recover application within a short period of time, it is necessary to Primary database (i.e. active-standby switch) is served as using slave, slave database and host data base data how is judged It is whether consistent, how within a short period of time by slave database data recovery into consistent, as a technology difficulty Topic.
Leader follower replication is standby host duplicate host binlog daily records, and daily record time delay and network communication are write due to there is main frame The factor such as time delay and standby host playback daily record time delay, therefore certainly exist active and standby daily record asynchrony phenomenon.Current industry Identification master/slave data whether consistent usual way in boundary's substantially has two kinds:A kind of service application layer user is voluntarily in master The newly-increased monitoring table of database, regularly updates the timestamp in the table, when management module is monitored in active and standby machine monitoring table Between stamp difference judge master/slave data synchronization discrepancy away from situation.Another is increased respectively in database standby machine The current binlog positions of database are inquired about in DBAgent proxy modules, timing, management module are reported, by pipe Reason module judges standby machine data syn-chronization gap situation.
There is following drawback in both the above mode:
1st, third-party management module is introduced, interaction complexity is added, while when third party manages mould In the case of block breaks down, whole monitoring system paralysis can not realize switching when breaking down.
2nd, asked due to introducing third party's management module and being that timing is reported, therefore there is the time difference in the cycle Topic, the tps of well-known database application each second is thousands of, and this timing reports mechanism at least It is also second level, therefore greatly reduces judgement precision, it is impossible to ensures that standby machine is strongly consistent when switching, The industries such as insurance class, security class, the bank class high to security request data can not receive this scheme.
3rd, aforesaid way two works as database service normally, and the main DBAgent generations of monitoring data storehouse running situation Manage module abnormal, it is also possible to cause the active-standby switch of abnormal database.
The content of the invention
It is a primary object of the present invention to propose a kind of master/slave data storehouse switching method and apparatus, it is intended to solve existing When master/slave data storehouse is switched in technology, data precision is poor, complex operation, the problem of stability is low.
To achieve the above object, the present invention proposes a kind of master/slave data storehouse switching method, including:
Perform connection native database service operations;
Receive to client database transmission to client database current location;
If the frequency of failure of the connection native database service operations exceedes default number of times, described is judged Machine database is abnormal, and performs alarm operation or in the native database and described to being carried out between client database Active-standby switch is operated, or, if described receive the failure to client database current location sent to client database Number of times exceed default number of times, then perform alarm operation or the native database and it is described to client database it Between carry out active-standby switch operation.
Preferably, the step of execution connection native database service operations include:
Perform connection database service operation, timing acquisition native database current location;
It is described receive to client database send to client database current location the step of include:
Receive client database is sent to client database current location, by the native database current location with It is described that client database current location is compared;
It is described to receive to client database transmission to client database current location, by the native database present bit Put with it is described client database current location is compared the step of after, in addition to:
When the native database current location with the difference to client database current location more than default During threshold value, alarm operation is performed.
Preferably, if the frequency of failure of the connection native database service operations exceedes default number of times, Then judge that the native database is abnormal, and perform alarm operation or in the native database and the opposite end number Include according to the step of carrying out active-standby switch operation between storehouse:
If the native database is standby database, described is main database to client database, then performs alarm behaviour Make, and continue executing with connecting detection operation;
If the native database is primary database, described is standby database to client database, then parses described The journal file of machine database, obtains the rearmost position of the native database, and is held according to the rearmost position Row active-standby switch is operated.
Preferably, the step of execution active-standby switch is operated includes:
If the rearmost position of the primary database is not sky, contrast the rearmost position of the primary database with it is described Standby database current location, wherein, if the standby database current location is equal to the last position of the primary database Put, then perform automatically switching operation, if the standby database current location is less than the last position of the primary database Put, then whether the automatically switching operation is performed according to business need decision-making;
If the rearmost position of the primary database is sky, contrast the current location of the primary database with it is described standby Database current location, wherein, if the standby database current location is more than or equal to working as the primary database Front position, then perform the automatically switching operation, otherwise, then according to performing whether business need decision-making certainly Dynamic handover operation.
Preferably, the automatically switching operation includes:
The switching standby database is primary database, and after the standby database service recovers, recovers master again Standby replication relation.
Preferably, the step of rearmost position of the acquisition native database includes:
Obtain the current log file list of the native database;
Since last journal file in the current log file list scan, and from it is described last The rearmost position of the native database is obtained in last event of individual journal file;
If last described event can not be found from last described journal file, scanning it is described last A upper journal file for individual journal file, until finding last described event.
To achieve the above object, the present invention also proposes a kind of master/slave data storehouse switching device, including:
Link block, for performing connection native database service operations;
Position module, for receiving to client database transmission to client database current location;
Performing module, if the frequency of failure for the connection native database service operations exceedes default number of times, Then judge that the native database is abnormal, and perform alarm operation or in the native database and the opposite end number According to progress active-standby switch operation between storehouse, or, if the reception working as to client database to client database transmission The frequency of failure of front position exceedes default number of times, then performs alarm operation or in the native database and described To carrying out active-standby switch operation between client database.
Preferably, the link block, is additionally operable to perform connection native database service operations, timing acquisition sheet Machine database current location;
The position module, is additionally operable to receive to client database transmission to client database current location, will be described Client database current location is compared with described for native database current location;
Described device also includes:
Alarm module, for when the native database current location and the difference to client database current location When value is more than default threshold value, alarm operation is performed.
Preferably, the performing module, if it is standby database, the opposite end number to be additionally operable to the native database It is primary database according to storehouse, then performs alarm operation, and continue executing with connecting detection operation;If the native data Storehouse is primary database, and described is standby database to client database, then parses the journal file of the native database, The rearmost position of the native database is obtained, and active-standby switch operation is performed according to the rearmost position.
Preferably, the performing module, if the rearmost position for being additionally operable to the primary database is not sky, is contrasted The rearmost position of the primary database and the standby database current location, wherein, if the standby database is current Position is equal to the rearmost position of the primary database, then performs automatically switching operation, if the standby database is current Position is less than the rearmost position of the primary database, then whether performs the automatic switchover according to business need decision-making Operation;If the rearmost position of the primary database is sky, contrast the current location of the primary database with it is described Standby database current location, wherein, if the standby database current location is more than or equal to the primary database Current location, then perform the automatically switching operation, otherwise, then according to performing whether business need decision-making Automatically switching operation.
Preferably, the performing module, if being additionally operable to the user for unspecified persons, performs and specifies orientation Information ties up card operation.
Preferably, the performing module, is additionally operable to obtain the current log file list of the native database; Scanned since last journal file in the current log file list, and from last described day The rearmost position of the native database is obtained in last event of will file;If can not from it is described last Individual journal file finds last described event, then scans a upper daily record for last journal file File, until finding last described event.
The invention discloses a kind of master/slave data storehouse switching method and apparatus, taken by performing connection native database Business operation;Receive to client database transmission to client database current location;If connecting database service operation The frequency of failure exceedes default number of times, then judges that native database is abnormal, and performs alarm operation or in the machine number According to storehouse and to carrying out active-standby switch operation between client database, or, if receiving the opposite end sent to client database The frequency of failure of database current location exceedes default number of times, then perform alarm operation or in native database and To carrying out active-standby switch operation between client database, when solving that master/slave data storehouse is switched in the prior art, Data precision is poor, complex operation, the problem of stability is low.Realize monitoring in real time and grasp the synchronization of master/slave data storehouse Gap situation, simplifies operation, it is ensured that data consistency, while avoid switching by mistake.
Brief description of the drawings
Fig. 1 is the schematic flow sheet of master/slave data storehouse switching method first embodiment of the present invention;
Fig. 2 is duplication monitoring management Organization Chart in master/slave data storehouse in the embodiment of the present invention;
Fig. 3 is the schematic flow sheet of master/slave data storehouse switching method second embodiment of the present invention;
If the frequency of failure that Fig. 4 is the connection native database service operations in the embodiment of the present invention exceedes default Number of times, then judge that the native database is abnormal, and perform alarm operation or in the native database and institute State a kind of schematic flow sheet the step of to carrying out active-standby switch operation between client database;
Fig. 5 is a kind of schematic flow sheet that the step of active-standby switch is operated is performed in the embodiment of the present invention;
A kind of schematic flow sheet for the step of Fig. 6 is automatically switching operation in the embodiment of the present invention;
Fig. 7 is that a kind of flow the step of obtaining the rearmost position of the native database in the embodiment of the present invention is shown It is intended to;
Fig. 8 is binlog iog location variation relation figures before and after active-standby switch in the embodiment of the present invention;
Fig. 9 is the high-level schematic functional block diagram of master/slave data storehouse switching device first embodiment of the present invention;
Figure 10 is the high-level schematic functional block diagram of master/slave data storehouse switching device second embodiment of the present invention.
The realization, functional characteristics and advantage of the object of the invention will be described further referring to the drawings in conjunction with the embodiments.
Embodiment
It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, it is not used to limit this Invention.
As shown in figure 1, first embodiment of the invention proposes a kind of master/slave data storehouse switching method, including:
Step S10, performs connection native database service operations.
The executive agent of the inventive method can be a kind of database management platform or database server, specifically should It will be specifically described for primary database or standby database in following description, other energy are also not limited to certainly Enough realize the equipment or server of master/slave data storehouse switching.
Wherein, the present invention is main ensures that database master/slave data is same by using MariaDB and binlog daily records Step process can be monitored, it is ensured that quick automatic switching when database is abnormal.
Wherein, can be in master/slave data place in its upper side administration database broker software when implementing DBAgent (or other can realize the software of identical function), DBAgent are a kind of database broker software, It can be used for monitoring data storehouse service operation situation, parse binlog journal files, can be used when breaking down In switching control process;Wherein, can be by the relevant action performed in MariaDB database runnings It recorded in binlog journal files, in case reading synchrodata from database, MariaDB databases were performed Cheng Zhong, when producing binlog journal files, accordingly providing binlog positions, i.e. current log position, (length is whole Shape value).
Specifically, the DBAgent timings monitoring native database running situation and current binlog in master/slave data storehouse Newest GTID in daily record, meanwhile, standby machine database running situation is shared between master/slave data storehouse mutually.
When native database is primary database, when being standby database to client database:
The DBAgent timings of primary database connect primary database by MYSQL agreements with specific user Serve port, inquires about and obtains native database current location (current gtid_current_pos), and remembered Record is updated, and the DBAgent for being sent to standby database by heartbeat message interface is recorded.
When native database is for database, when being main database to client database:
The DBAgent timings of standby database connect standby database by MYSQL agreements with specific user Serve port, inquires about and obtains native database current location (current gtid_current_pos), and remembered Record is updated, and the DBAgent for being sent to primary database by heartbeat message interface is recorded.
Step S20, is received to client database transmission to client database current location.
Specifically, when native database is primary database, when being standby database to client database:
The DBAgent of primary database receives the heartbeat message that the DBAgent of standby database is sent, the standby number of record According to the current gtid_current_pos positions in storehouse.
When native database is for database, when being main database to client database:
The DBAgent of standby database receives the heartbeat message that the DBAgent of primary database is sent, and records main number According to the current gtid_current_pos positions in storehouse.
Step S30, if the frequency of failure of the connection native database service operations exceedes default number of times, Judge that the native database is abnormal, and perform alarm operation or in the native database and described to end data Active-standby switch operation is carried out between storehouse, or, if described receive to the current to client database of client database transmission The frequency of failure of position exceedes default number of times, then performs alarm operation or in the native database and described right Active-standby switch operation is carried out between client database.
Specifically, when native database is for database, when being main database to client database:
If the DBAgent connection database services of standby database unsuccessfully exceed stipulated number (such as 10 times, this Number of times can system pre-set, can also be modified by user according to actual use situation), judge Current primary database is abnormal, continues executing with connecting detection operation.
When native database is primary database, when being standby database to client database:
If the DBAgent connection database services of standby database unsuccessfully exceed stipulated number (such as 10 times, this Number of times can system pre-set, can also be modified by user according to actual use situation), judge Current primary database is abnormal, parses the journal file of primary database, obtains the rearmost position of primary database, and root Active-standby switch operation is performed according to rearmost position, when implementing, following manner can be taken:
1st, by way of parsing database binlog journal files, primary database is obtained last Gtid_current_pos positions, are recorded as last_pos positions;
2nd, the DBAgent of primary database sends handover request message to the DBAgent of standby database, the message Include the last_pos positions of primary database;
3rd, whether the DBAgent continuation timing Test database services of primary database are normal, until database clothes Business recovers;
4th, the last_pos positions of primary databases of the DBAgent of primary database in handover request, are initiated Active-standby switch flow, wherein:
If the rearmost position of primary database is not sky, rearmost position and the standby database for contrasting primary database are current Position, wherein, if standby database current location is equal to the rearmost position of primary database, perform behaviour of automatically switching Make, if standby database current location is less than the rearmost position of primary database, whether held according to business need decision-making Row automatically switching operation;
If the rearmost position of primary database is sky, the current location of primary database and standby database present bit are contrasted Put, wherein, if standby database current location is more than or equal to the current location of primary database, execution is cut automatically Operation is changed, otherwise, then whether automatically switching operation is performed according to business need decision-making.
Above-mentioned automatically switching operation is specially:The standby database of switching is primary database, and extensive in standby database service After multiple, recover active and standby replication relation again.
Or, when host data base is primary database, when being standby database to client database:
If the DBAgent of primary database is sent beyond the DBAgent that stipulated number does not receive primary database Heartbeat message, then perform alarm alarm operation.
When host data base is for database, when being main database to client database:
If the DBAgent of standby database is sent beyond the DBAgent that stipulated number does not receive primary database Heartbeat message, then pass through MYSQL agreements and connect primary database serve port and obtain primary database current location Gtid_current_pos, if obtaining the DBAgent process operation exceptions for successfully illustrating primary database, database Service is normal, without active-standby switch is initiated, only need to alert and record correlation log, if obtaining failure, explanation Primary database DBAgent processes and database service are abnormal, can now initiate active-standby switch request.
In addition, as shown in Fig. 2 for leader follower replication monitoring management paralell composition, being described in detail below:
Primary database perform DDL sentences or comprising update SQL affairs when, for the affairs distribute an overall situation The GTID numberings of unique order, before affairs are submitted write-in binary system binlog journal files be synchronized to simultaneously from Database, the binlog log information synchrodatas of primary database are read from database, reply execution corresponding SQL statement, so as to reach and primary database data syn-chronization;
Database broker software DBAgent periodic monitor native database service operation situations, pass through MYSQL Whether the operation of agreement connected reference native database monitoring data storehouse is normal, while it is current to obtain native database The timing of gtid_current_pos positions sends heartbeat message and gives opposite end DBAgent, DBAgent to receive opposite end The gtid_current_pos positions of new record opposite end database are solved after heartbeat message, native database and opposite end is compared The gtid_current_pos positions of database, the data syn-chronization situation of master-slave database is judged according to difference, works as master Exceed setting range from database gtid_current_pos gaps and carry out the related measures such as Real-time Alarm.
Further, DBAgent transmissions in opposite end are not received in database broker software DBAgent certain times Heartbeat message after, actively by MYSQL agreement peer end of the connection database services, judge to client database take Whether business is normal, while obtaining the gtid_current_pos positions to client database, judges if connection failure It is abnormal to client database, whether active-standby switch is initiated according to principal and subordinate role's decision-making of database.
By such scheme, the invention provides a kind of master/slave data storehouse switching method, this method can be supervised in real time Principal and subordinate's data syn-chronization gap situation is grasped in control, and system is understood indirectly writes transaction load situation of change;Eliminate Tripartite's management assembly, direct hedge whole system unavailable problem caused by third party's management assembly failure;Letter Installation and deployment are also simplify while changing processing logic, DBAgent can carry out software binding, each number with DB It is unified easy according to storehouse node deployment;Quick identification standby machine database data is inconsistent, can be automatic when data are consistent Active-standby switch is carried out, and builds new leader follower replication relation.Data can automate generation differentiation SQL when inconsistent Script, is that manual intervention is saved the time, and height ensures data consistency;It is different in DBAgent processes itself Regular data storehouse is serviced under normal circumstances, it is to avoid unnecessary mistake switching.
As shown in figure 3, second embodiment of the invention proposes a kind of master/slave data storehouse switching method, including:
Step S11, performs connection native database service operations, timing acquisition native database current location.
Specifically, the DBAgent timings monitoring native database running situation and current binlog in master/slave data storehouse Newest GTID in daily record, meanwhile, standby machine database running situation is shared between master/slave data storehouse mutually.
When native database is primary database, when being standby database to client database:
The DBAgent timings of primary database connect primary database by MYSQL agreements with specific user Serve port, inquires about and obtains native database current location (current gtid_current_pos), and remembered Record is updated, and the DBAgent for being sent to standby database by heartbeat message interface is recorded.
When native database is for database, when being main database to client database:
The DBAgent timings of standby database connect standby database by MYSQL agreements with specific user Serve port, inquires about and obtains native database current location (current gtid_current_pos), and remembered Record is updated, and the DBAgent for being sent to primary database by heartbeat message interface is recorded.
Step S21, is received to client database transmission to client database current location, by the native database Client database current location is compared with described for current location.
Specifically, when native database is primary database, when being standby database to client database:
The DBAgent of primary database receives the heartbeat message that the DBAgent of standby database is sent, the standby number of record According to the current gtid_current_pos positions in storehouse, the current gtid_current_pos positions of primary database are compared and standby The current gtid_current_pos positions of database.
When native database is for database, when being main database to client database:
The DBAgent of standby database receives the heartbeat message that the DBAgent of primary database is sent, and records main number According to the current gtid_current_pos positions in storehouse, the current gtid_current_pos positions of primary database are compared and standby The current gtid_current_pos positions of database.
Step S40, when the native database current location and the difference to client database current location are big When default threshold value, alarm operation is performed.
Specifically, when the current gtid_current_pos positions of primary database and for the current of database Gtid_current_pos positions difference be more than configuration threshold value when (threshold value can system pre-set, Can be modified by user according to actual use situation), corresponding measure is taken, is such as alerted.
By such scheme, the invention provides a kind of master/slave data storehouse switching method, this method can be supervised in real time Principal and subordinate's data syn-chronization gap situation is grasped in control, and system is understood indirectly writes transaction load situation of change;Eliminate Tripartite's management assembly, direct hedge whole system unavailable problem caused by third party's management assembly failure;Letter Installation and deployment are also simplify while changing processing logic, DBAgent can carry out software binding, each number with DB It is unified easy according to storehouse node deployment;Quick identification standby machine database data is inconsistent, can be automatic when data are consistent Active-standby switch is carried out, and builds new leader follower replication relation.Data can automate generation differentiation SQL when inconsistent Script, is that manual intervention is saved the time, and height ensures data consistency;It is different in DBAgent processes itself Regular data storehouse is serviced under normal circumstances, it is to avoid unnecessary mistake switching.
Further, in order to better ensure that the uniformity of reserve database switching evidence, reference picture 4 is In the specific embodiment of the invention, if the frequency of failure of the connection native database service operations is more than default Number of times, then judge that the native database is abnormal, and performs alarm operation or in the native database and described A kind of schematic flow sheet of the step of to carrying out active-standby switch operation between client database.
As a kind of embodiment, above-mentioned steps S30 includes:
Step S31, if the native database is standby database, described is main database to client database, then Alarm operation is performed, and continues executing with connecting detection operation.
Specifically, when native database is for database, when being main database to client database:
If the DBAgent connection database services of standby database unsuccessfully exceed stipulated number (such as 10 times, this Number of times can system pre-set, can also be modified by user according to actual use situation), judge Current primary database is abnormal, continues executing with connecting detection operation.
Step S32, if the native database is primary database, described is standby database to client database, then The journal file of the native database is parsed, the rearmost position of the native database is obtained, and according to described Rearmost position performs active-standby switch operation.
Specifically, when native database is primary database, when being standby database to client database:
If the DBAgent connection database services of standby database unsuccessfully exceed stipulated number (such as 10 times, this Number of times can system pre-set, can also be modified by user according to actual use situation), judge Current primary database is abnormal, parses the journal file of primary database, obtains the rearmost position of primary database, and root Active-standby switch operation is performed according to rearmost position, when implementing, following manner can be taken:
1st, by way of parsing database binlog journal files, primary database is obtained last Gtid_current_pos positions, are recorded as last_pos positions;
2nd, the DBAgent of primary database sends handover request message to the DBAgent of standby database, the message Include the last_pos positions of primary database;
3rd, whether the DBAgent continuation timing Test database services of primary database are normal, until database clothes Business recovers;
4th, the last_pos positions of primary databases of the DBAgent of primary database in handover request, are initiated Active-standby switch flow, wherein:
If the rearmost position of primary database is not sky, rearmost position and the standby database for contrasting primary database are current Position, wherein, if standby database current location is equal to the rearmost position of primary database, perform behaviour of automatically switching Make, if standby database current location is less than the rearmost position of primary database, whether held according to business need decision-making Row automatically switching operation;
If the rearmost position of primary database is sky, the current location of primary database and standby database present bit are contrasted Put, wherein, if standby database current location is more than or equal to the current location of primary database, execution is cut automatically Operation is changed, otherwise, then whether automatically switching operation is performed according to business need decision-making.
By such scheme, the invention provides a kind of master/slave data storehouse switching method, this method passes through in the machine When database is abnormal, the Different treatments that master/slave data storehouse is performed have been better achieved real-time monitoring and have grasped master Standby database synchronization gap situation, simplifies operation, it is ensured that data consistency, while avoid switching by mistake.
Further, in order to better ensure that the uniformity of reserve database switching evidence, reference picture 5 is In the specific embodiment of the invention, a kind of schematic flow sheet for the step of active-standby switch is operated is performed.
As a kind of embodiment, above-mentioned steps S32 includes:
Step S321, if the rearmost position of the primary database is not sky, contrasts the primary database most Position and the standby database current location afterwards, wherein, if the standby database current location is equal to the main number According to the rearmost position in storehouse, then automatically switching operation is performed, if the standby database current location is less than the main number According to the rearmost position in storehouse, then whether the automatically switching operation is performed according to business need decision-making.
Specifically, if the last_pos positions of primary database are not sky, the last GTID of primary database is compared Whether position last_pos is consistent with the current gtid_current_pos of standby database, if standby database Gtid_current_pos then carries out automatically switching operation equal to primary database last_pos, if standby database Gtid_current_pos is less than primary database last_pos and illustrates the data not yet Complete Synchronization of primary database to main number Whether, according to storehouse, master/slave data storehouse data are inconsistent, at this point it is possible to be needed to automatically switch according to business need decision-making And record the log information of correlation.
Wherein, according to MariaDB replicating principle, it is impossible to standby database gtid_current_pos occur big In primary database last_pos situation.
Step S322, if the rearmost position of the primary database is sky, contrasts the current of the primary database Position and the standby database current location, wherein, if the standby database current location is more than or equal to described The current location of primary database, then perform the automatically switching operation, otherwise, then be according to business need decision-making It is no to perform the automatically switching operation.
Specifically, if primary database last_pos positions are sky, the current GTID positions of primary database are compared Gtid_current_pos is put whether consistent with the current gtid_current_pos of standby database, if standby database More than or equal to primary database gtid_current_pos positions, then automatically switching operation is carried out, otherwise, then explanation is led The data of database not yet Complete Synchronization is to standby database, and master/slave data storehouse data are inconsistent, at this point it is possible to root Whether need to automatically switch and record the log information of correlation according to business need decision-making.
By such scheme, the invention provides a kind of master/slave data storehouse switching method, this method passes through according to not Corresponding active-standby switch operation is performed with situation, real-time monitoring has been better achieved and has grasped master/slave data storehouse synchronization discrepancy Away from situation, simplify operation, it is ensured that data consistency, while avoid switching by mistake.
Further, in order to better ensure that the uniformity of reserve database switching evidence, reference picture 6 is In the specific embodiment of the invention, a kind of schematic flow sheet for the step of performing automatically switching operation.
As a kind of embodiment, above-mentioned steps S32 includes:
Step S323, it is primary database to switch the standby database, and after the standby database service recovers, Again active and standby replication relation is recovered.
Specifically, the standby database of DBAgent switchings is primary database, and main former database is set into standby database, After standby database service recovers, DBAgent recovers master/slave data storehouse replication relation again;When master/slave data storehouse When data are inconsistent, then need to parse the binlog journal files of former primary database, from standby database The SQL statement that all GTID after being parsed at gtid_current_pos positions are related to, generation forward direction SQL After sentence, make it that former master/slave data storehouse data recovery is consistent after former standby database supplement is finished.
By such scheme, the invention provides a kind of master/slave data storehouse switching method, this method is by performing certainly Dynamic handover operation, has been better achieved real-time monitoring and has grasped master/slave data storehouse synchronization discrepancy away from situation, simplified operation, Ensure data consistency, while avoid switching by mistake.
Further, in order to better ensure that the uniformity of reserve database switching evidence, reference picture 7 is In the specific embodiment of the invention, a kind of flow signal for the step of obtaining the rearmost position of the native database Figure.
As a kind of embodiment, above-mentioned steps S32 includes:
Step S324, obtains the current log file list of the native database.
Specifically, when host data base services exception, DBAgent is by calling mysqlbinlog instruments to obtain Take the GTID positions last_pos that database is last.
Wherein, the current binlog of index file acquisitions under database binlog binary log files is passed through Listed files.
Step S325, is scanned since last journal file in the current log file list, and The rearmost position of the native database is obtained from last event of last journal file.
Specifically, scanned since last binlog journal file, this binlog file is found in scanning Last gtid event (GTID_LOG_EVENT), obtains last gtid as last_pos.
Step S326, if last described event can not be found from last described journal file, sweeps A upper journal file for last journal file is retouched, until finding last described event.
Specifically, if current binlog does not find gtid events, i.e., no affairs submit record at this In binlog files, then be scanned for a binlog file, move in circles, until finding last gtid.
Further, the method for specified gtid_current_pos positions is searched with above-mentioned by binlog journal files Search last_pos methods.
In addition, as shown in figure 8, master/slave data storehouse corresponding binlog front and rear for the operation of MariaDB active-standby switch Iog location change situation.
Wherein, PosA is the gtid_current_pos in the normal heartbeat message that former primary database last time is reported Position;Last_pos be former primary database last write affairs and be actually written into binlog binary logs most Big GTID positions;PosB is last affairs that former standby host database replicates binlog daily records from primary database Corresponding GTID positions;When both Last_pos, PosB coincidence are equal, master/slave data is completely the same, can It is automatic to carry out active-standby switch;When Last_pos unknown (physical machine such as power down suspension abnormal conditions), PosB is more than Whether master/slave data is consistent unknown during equal to PosA;Now carry out after active-standby switch, treat that original host recovers abnormal Need to reaffirm Last_pos positions and PosB relation afterwards, it is active and standby if Last_pos is more than PosB Variantization binlog between machine, otherwise standby machine data are consistent;When the unknown (things such as power down suspension of Last_pos Reason machine abnormal conditions), when PosB is less than PosA, former standby host data substantially fall behind original host, standby machine data It is inconsistent.
By such scheme, the invention provides a kind of master/slave data storehouse switching method, it has been better achieved in real time Monitoring grasps master/slave data storehouse synchronization discrepancy away from situation, simplifies operation, it is ensured that data consistency, while avoid cutting by mistake Change.
Based on the realization of above method embodiment, the present invention also provides corresponding device embodiment.
As shown in figure 9, first embodiment of the invention proposes a kind of master/slave data storehouse switching device, including:
Link block 100, for performing connection native database service operations.
Wherein, the present invention is main ensures that database master/slave data is same by using MariaDB and binlog daily records Step process can be monitored, it is ensured that quick automatic switching when database is abnormal.
Wherein, can be in master/slave data place in its upper side administration database broker software when implementing DBAgent (or other can realize the software of identical function), DBAgent are a kind of database broker software, It can be used for monitoring data storehouse service operation situation, parse binlog journal files, can be used when breaking down In switching control process;Wherein, can be by the relevant action performed in MariaDB database runnings It recorded in binlog journal files, in case reading synchrodata from database, MariaDB databases were performed Cheng Zhong, when producing binlog journal files, accordingly providing binlog positions, i.e. current log position, (length is whole Shape value).
Specifically, the DBAgent timings monitoring native database running situation and current binlog in master/slave data storehouse Newest GTID in daily record, meanwhile, standby machine database running situation is shared between master/slave data storehouse mutually.
When native database is primary database, when being standby database to client database:
The DBAgent timings of primary database connect primary database by MYSQL agreements with specific user Serve port, inquires about and obtains native database current location (current gtid_current_pos), and remembered Record is updated, and the DBAgent for being sent to standby database by heartbeat message interface is recorded.
When native database is for database, when being main database to client database:
The DBAgent timings of standby database connect standby database by MYSQL agreements with specific user Serve port, inquires about and obtains native database current location (current gtid_current_pos), and remembered Record is updated, and the DBAgent for being sent to primary database by heartbeat message interface is recorded.
Position module 200, for receiving to client database transmission to client database current location.
Specifically, when native database is primary database, when being standby database to client database:
The DBAgent of primary database receives the heartbeat message that the DBAgent of standby database is sent, the standby number of record According to the current gtid_current_pos positions in storehouse.
When native database is for database, when being main database to client database:
The DBAgent of standby database receives the heartbeat message that the DBAgent of primary database is sent, and records main number According to the current gtid_current_pos positions in storehouse.
Performing module 300, if the frequency of failure for the connection native database service operations is more than default Number of times, then judge that the native database is abnormal, and performs alarm operation or in the native database and described To carrying out active-standby switch operation between client database, or, if described receive the opposite end number sent to client database Exceed default number of times according to the frequency of failure of storehouse current location, then perform alarm operation or in the native database And it is described to carrying out active-standby switch operation between client database.
Specifically, when native database is for database, when being main database to client database:
If the DBAgent connection database services of standby database unsuccessfully exceed stipulated number (such as 10 times, this Number of times can system pre-set, can also be modified by user according to actual use situation), judge Current primary database is abnormal, continues executing with connecting detection operation.
When native database is primary database, when being standby database to client database:
If the DBAgent connection database services of standby database unsuccessfully exceed stipulated number (such as 10 times, this Number of times can system pre-set, can also be modified by user according to actual use situation), judge Current primary database is abnormal, parses the journal file of primary database, obtains the rearmost position of primary database, and root Active-standby switch operation is performed according to rearmost position, when implementing, following manner can be taken:
1st, by way of parsing database binlog journal files, primary database is obtained last Gtid_current_pos positions, are recorded as last_pos positions;
2nd, the DBAgent of primary database sends handover request message to the DBAgent of standby database, the message Include the last_pos positions of primary database;
3rd, whether the DBAgent continuation timing Test database services of primary database are normal, until database clothes Business recovers;
4th, the last_pos positions of primary databases of the DBAgent of primary database in handover request, are initiated Active-standby switch flow, wherein:
If the rearmost position of primary database is not sky, rearmost position and the standby database for contrasting primary database are current Position, wherein, if standby database current location is equal to the rearmost position of primary database, perform behaviour of automatically switching Make, if standby database current location is less than the rearmost position of primary database, whether held according to business need decision-making Row automatically switching operation;
If the rearmost position of primary database is sky, the current location of primary database and standby database present bit are contrasted Put, wherein, if standby database current location is more than or equal to the current location of primary database, execution is cut automatically Operation is changed, otherwise, then whether automatically switching operation is performed according to business need decision-making.
Above-mentioned automatically switching operation is specially:The standby database of switching is primary database, and extensive in standby database service After multiple, recover active and standby replication relation again.
Or, when host data base is primary database, when being standby database to client database:
If the DBAgent of primary database is sent beyond the DBAgent that stipulated number does not receive primary database Heartbeat message, then perform alarm alarm operation.
When host data base is for database, when being main database to client database:
If the DBAgent of standby database is sent beyond the DBAgent that stipulated number does not receive primary database Heartbeat message, then pass through MYSQL agreements and connect primary database serve port and obtain primary database current location Gtid_current_pos, if obtaining the DBAgent process operation exceptions for successfully illustrating primary database, database Service is normal, without active-standby switch is initiated, only need to alert and record correlation log, if obtaining failure, explanation Primary database DBAgent processes and database service are abnormal, can now initiate active-standby switch request.
In addition, as shown in Fig. 2 for leader follower replication monitoring management paralell composition, being described in detail below:
Primary database perform DDL sentences or comprising update SQL affairs when, for the affairs distribute an overall situation The GTID numberings of unique order, before affairs are submitted write-in binary system binlog journal files be synchronized to simultaneously from Database, the binlog log information synchrodatas of primary database are read from database, reply execution corresponding SQL statement, so as to reach and primary database data syn-chronization;
Database broker software DBAgent periodic monitor native database service operation situations, pass through MYSQL Whether the operation of agreement connected reference native database monitoring data storehouse is normal, while it is current to obtain native database The timing of gtid_current_pos positions sends heartbeat message and gives opposite end DBAgent, DBAgent to receive opposite end The gtid_current_pos positions of new record opposite end database are solved after heartbeat message, native database and opposite end is compared The gtid_current_pos positions of database, the data syn-chronization situation of master-slave database is judged according to difference, works as master Exceed setting range from database gtid_current_pos gaps and carry out the related measures such as Real-time Alarm.
Further, DBAgent transmissions in opposite end are not received in database broker software DBAgent certain times Heartbeat message after, actively by MYSQL agreement peer end of the connection database services, judge to client database take Whether business is normal, while obtaining the gtid_current_pos positions to client database, judges if connection failure It is abnormal to client database, whether active-standby switch is initiated according to principal and subordinate role's decision-making of database.
By such scheme, the invention provides a kind of master/slave data storehouse switching device, this method can be supervised in real time Principal and subordinate's data syn-chronization gap situation is grasped in control, and system is understood indirectly writes transaction load situation of change;Eliminate Tripartite's management assembly, direct hedge whole system unavailable problem caused by third party's management assembly failure;Letter Installation and deployment are also simplify while changing processing logic, DBAgent can carry out software binding, each number with DB It is unified easy according to storehouse node deployment;Quick identification standby machine database data is inconsistent, can be automatic when data are consistent Active-standby switch is carried out, and builds new leader follower replication relation.Data can automate generation differentiation SQL when inconsistent Script, is that manual intervention is saved the time, and height ensures data consistency;It is different in DBAgent processes itself Regular data storehouse is serviced under normal circumstances, it is to avoid unnecessary mistake switching.
As shown in Figure 10, second embodiment of the invention proposes a kind of master/slave data storehouse switching device, wherein:
Above-mentioned link block 100, is additionally operable to perform connection native database service operations, timing acquisition the machine number According to storehouse current location.
Specifically, the DBAgent timings monitoring native database running situation and current binlog in master/slave data storehouse Newest GTID in daily record, meanwhile, standby machine database running situation is shared between master/slave data storehouse mutually.
When native database is primary database, when being standby database to client database:
The DBAgent timings of primary database connect primary database by MYSQL agreements with specific user Serve port, inquires about and obtains native database current location (current gtid_current_pos), and remembered Record is updated, and the DBAgent for being sent to standby database by heartbeat message interface is recorded.
When native database is for database, when being main database to client database:
The DBAgent timings of standby database connect standby database by MYSQL agreements with specific user Serve port, inquires about and obtains native database current location (current gtid_current_pos), and remembered Record is updated, and the DBAgent for being sent to primary database by heartbeat message interface is recorded.
Above-mentioned position module 200, is additionally operable to receive to client database transmission to client database current location, will Client database current location is compared with described for the native database current location.
Specifically, when native database is primary database, when being standby database to client database:
The DBAgent of primary database receives the heartbeat message that the DBAgent of standby database is sent, the standby number of record According to the current gtid_current_pos positions in storehouse, the current gtid_current_pos positions of primary database are compared and standby The current gtid_current_pos positions of database.
When native database is for database, when being main database to client database:
The DBAgent of standby database receives the heartbeat message that the DBAgent of primary database is sent, and records main number According to the current gtid_current_pos positions in storehouse, the current gtid_current_pos positions of primary database are compared and standby The current gtid_current_pos positions of database.
The device also includes:
Alarm module 400, for when the native database current location with it is described to client database current location Difference be more than default threshold value when, perform alarm operation.
Specifically, when the current gtid_current_pos positions of primary database and for the current of database Gtid_current_pos positions difference be more than configuration threshold value when (threshold value can system pre-set, Can be modified by user according to actual use situation), corresponding measure is taken, is such as alerted.
By such scheme, the invention provides a kind of master/slave data storehouse switching device, this method can be supervised in real time Principal and subordinate's data syn-chronization gap situation is grasped in control, and system is understood indirectly writes transaction load situation of change;Eliminate Tripartite's management assembly, direct hedge whole system unavailable problem caused by third party's management assembly failure;Letter Installation and deployment are also simplify while changing processing logic, DBAgent can carry out software binding, each number with DB It is unified easy according to storehouse node deployment;Quick identification standby machine database data is inconsistent, can be automatic when data are consistent Active-standby switch is carried out, and builds new leader follower replication relation.Data can automate generation differentiation SQL when inconsistent Script, is that manual intervention is saved the time, and height ensures data consistency;It is different in DBAgent processes itself Regular data storehouse is serviced under normal circumstances, it is to avoid unnecessary mistake switching.
Further, in order to better ensure that reserve database switching evidence uniformity, above-mentioned performing module 300, if it is standby database to be additionally operable to the native database, described is main database to client database, then holds Row alarm operation, and continue executing with connecting detection operation;If the native database is primary database, described right Client database is standby database, then parses the journal file of the native database, obtains the native database Rearmost position, and according to the rearmost position perform active-standby switch operation.
Specifically, when native database is for database, when being main database to client database:
If the DBAgent connection database services of standby database unsuccessfully exceed stipulated number (such as 10 times, this Number of times can system pre-set, can also be modified by user according to actual use situation), judge Current primary database is abnormal, continues executing with connecting detection operation.
Then, when native database is primary database, when being standby database to client database:
If the DBAgent connection database services of standby database unsuccessfully exceed stipulated number (such as 10 times, this Number of times can system pre-set, can also be modified by user according to actual use situation), judge Current primary database is abnormal, parses the journal file of primary database, obtains the rearmost position of primary database, and root Active-standby switch operation is performed according to rearmost position, when implementing, following manner can be taken:
1st, by way of parsing database binlog journal files, primary database is obtained last Gtid_current_pos positions, are recorded as last_pos positions;
2nd, the DBAgent of primary database sends handover request message to the DBAgent of standby database, the message Include the last_pos positions of primary database;
3rd, whether the DBAgent continuation timing Test database services of primary database are normal, until database clothes Business recovers;
4th, the last_pos positions of primary databases of the DBAgent of primary database in handover request, are initiated Active-standby switch flow, wherein:
If the rearmost position of primary database is not sky, rearmost position and the standby database for contrasting primary database are current Position, wherein, if standby database current location is equal to the rearmost position of primary database, perform behaviour of automatically switching Make, if standby database current location is less than the rearmost position of primary database, whether held according to business need decision-making Row automatically switching operation;
If the rearmost position of primary database is sky, the current location of primary database and standby database present bit are contrasted Put, wherein, if standby database current location is more than or equal to the current location of primary database, execution is cut automatically Operation is changed, otherwise, then whether automatically switching operation is performed according to business need decision-making.
By such scheme, the invention provides a kind of master/slave data storehouse switching device, this method passes through in the machine When database is abnormal, the Different treatments that master/slave data storehouse is performed have been better achieved real-time monitoring and have grasped master Standby database synchronization gap situation, simplifies operation, it is ensured that data consistency, while avoid switching by mistake.
Further, in order to better ensure that reserve database switching evidence uniformity, above-mentioned performing module 300, if the rearmost position for being additionally operable to the primary database is not sky, contrast the last position of the primary database Put with described for database current location, wherein, if the standby database current location is equal to the primary database Rearmost position, then automatically switching operation is performed, if the standby database current location is less than the primary database Rearmost position, then whether the automatically switching operation is performed according to business need decision-making;If the primary database Rearmost position be sky, then contrast the current location of the primary database and the standby database current location, its In, if the standby database current location is more than or equal to the current location of the primary database, perform described Whether automatically switching operation, otherwise, then perform the automatically switching operation according to business need decision-making.
Specifically, if the last_pos positions of primary database are not sky, the last GTID of primary database is compared Whether position last_pos is consistent with the current gtid_current_pos of standby database, if standby database Gtid_current_pos then carries out automatically switching operation equal to primary database last_pos, if standby database Gtid_current_pos is less than primary database last_pos and illustrates the data not yet Complete Synchronization of primary database to main number Whether, according to storehouse, master/slave data storehouse data are inconsistent, at this point it is possible to be needed to automatically switch according to business need decision-making And record the log information of correlation.
Wherein, according to MariaDB replicating principle, it is impossible to standby database gtid_current_pos occur big In primary database last_pos situation.
Then, if primary database last_pos positions are sky, the current GTID positions of primary database are compared Whether gtid_current_pos is consistent with the current gtid_current_pos of standby database, if standby database is more than Equal to primary database gtid_current_pos positions, then automatically switching operation is carried out, otherwise, then illustrate master data The data in storehouse not yet Complete Synchronization is to standby database, and master/slave data storehouse data are inconsistent, at this point it is possible to according to industry Business requires whether decision-making needs to automatically switch and record the log information of correlation.
By such scheme, the invention provides a kind of master/slave data storehouse switching device, this method passes through according to not Corresponding active-standby switch operation is performed with situation, real-time monitoring has been better achieved and has grasped master/slave data storehouse synchronization discrepancy Away from situation, simplify operation, it is ensured that data consistency, while avoid switching by mistake.
Further, in order to better ensure that reserve database switching evidence uniformity, above-mentioned performing module 300, it is primary database to be additionally operable to the switching standby database, and after the standby database service recovers, weight Newly recover active and standby replication relation.
Specifically, the standby database of DBAgent switchings is primary database, and main former database is set into standby database, After standby database service recovers, DBAgent recovers master/slave data storehouse replication relation again;When master/slave data storehouse When data are inconsistent, then need to parse the binlog journal files of former primary database, from standby database The SQL statement that all GTID after being parsed at gtid_current_pos positions are related to, generation forward direction SQL After sentence, make it that former master/slave data storehouse data recovery is consistent after former standby database supplement is finished.
By such scheme, the invention provides a kind of master/slave data storehouse switching device, this method is by performing certainly Dynamic handover operation, has been better achieved real-time monitoring and has grasped master/slave data storehouse synchronization discrepancy away from situation, simplified operation, Ensure data consistency, while avoid switching by mistake.
Further, in order to better ensure that reserve database switching evidence uniformity, above-mentioned performing module 300, it is additionally operable to obtain the current log file list of the native database;From current log file row Last journal file in table starts scanning, and from last event of last journal file The middle rearmost position for obtaining the native database;If described in can not being found from last described journal file most Latter event, then scan a upper journal file for last journal file, until find it is described most Latter event.
Specifically, when host data base services exception, DBAgent is by calling mysqlbinlog instruments to obtain Take the GTID positions last_pos that database is last.
Wherein, the current binlog of index file acquisitions under database binlog binary log files is passed through Listed files.
Then, scanned since last binlog journal file, scanning finds this binlog file most Latter gtid event (GTID_LOG_EVENT), obtains last gtid as last_pos.
Then, if current binlog does not find gtid events, i.e., no affairs submit record in this binlog In file, then be scanned for a binlog file, move in circles, until finding last gtid.
Further, the method for specified gtid_current_pos positions is searched with above-mentioned by binlog journal files Search last_pos methods.
In addition, as shown in figure 8, master/slave data storehouse corresponding binlog front and rear for the operation of MariaDB active-standby switch Iog location change situation.
Wherein, PosA is the gtid_current_pos in the normal heartbeat message that former primary database last time is reported Position;Last_pos be former primary database last write affairs and be actually written into binlog binary logs most Big GTID positions;PosB is last affairs that former standby host database replicates binlog daily records from primary database Corresponding GTID positions;When both Last_pos, PosB coincidence are equal, master/slave data is completely the same, can It is automatic to carry out active-standby switch;When Last_pos unknown (physical machine such as power down suspension abnormal conditions), PosB is more than Whether master/slave data is consistent unknown during equal to PosA;Now carry out after active-standby switch, treat that original host recovers abnormal Need to reaffirm Last_pos positions and PosB relation afterwards, it is active and standby if Last_pos is more than PosB Variantization binlog between machine, otherwise standby machine data are consistent;When the unknown (things such as power down suspension of Last_pos Reason machine abnormal conditions), when PosB is less than PosA, former standby host data substantially fall behind original host, standby machine data It is inconsistent.
By such scheme, the invention provides a kind of master/slave data storehouse switching device, it has been better achieved in real time Monitoring grasps master/slave data storehouse synchronization discrepancy away from situation, simplifies operation, it is ensured that data consistency, while avoid cutting by mistake Change.
The preferred embodiments of the present invention are these are only, are not intended to limit the scope of the invention, it is every to utilize Equivalent structure or equivalent flow conversion that description of the invention and accompanying drawing content are made, or be directly or indirectly used in Other related technical fields, are included within the scope of the present invention.

Claims (12)

1. a kind of master/slave data storehouse switching method, it is characterised in that methods described includes:
Perform connection native database service operations;
Receive to client database transmission to client database current location;
If the frequency of failure of the connection native database service operations exceedes default number of times, described is judged Machine database is abnormal, and performs alarm operation or in the native database and described to being carried out between client database Active-standby switch is operated, or, if described receive the failure to client database current location sent to client database Number of times exceed default number of times, then perform alarm operation or the native database and it is described to client database it Between carry out active-standby switch operation.
2. according to the method described in claim 1, it is characterised in that described to perform connection native database clothes The step of business operation, includes:
Perform connection native database service operations, timing acquisition native database current location;
It is described receive to client database send to client database current location the step of include:
Receive client database is sent to client database current location, by the native database current location with It is described that client database current location is compared;
It is described to receive to client database transmission to client database current location, by the native database present bit Put with it is described client database current location is compared the step of after, in addition to:
When the native database current location with the difference to client database current location more than default During threshold value, alarm operation is performed.
3. method according to claim 2, it is characterised in that if the connection native database The frequency of failure of service operations exceedes default number of times, then judges that the native database is abnormal, and perform alarm Operation or the native database and it is described between client database carry out active-standby switch operation the step of include:
If the native database is standby database, described is main database to client database, then performs alarm behaviour Make, and continue executing with connecting detection operation;
If the native database is primary database, described is standby database to client database, then parses described The journal file of machine database, obtains the rearmost position of the native database, and is held according to the rearmost position Row active-standby switch is operated.
4. method according to claim 3, it is characterised in that the step of the execution active-standby switch operation Suddenly include:
If the rearmost position of the primary database is not sky, contrast the rearmost position of the primary database with it is described Standby database current location, wherein, if the standby database current location is equal to the last position of the primary database Put, then perform automatically switching operation, if the standby database current location is less than the last position of the primary database Put, then whether the automatically switching operation is performed according to business need decision-making;
If the rearmost position of the primary database is sky, contrast the current location of the primary database with it is described standby Database current location, wherein, if the standby database current location is more than or equal to working as the primary database Front position, then perform the automatically switching operation, otherwise, then according to performing whether business need decision-making certainly Dynamic handover operation.
5. method according to claim 4, it is characterised in that the automatically switching operation includes:
The switching standby database is primary database, and after the standby database service recovers, recovers master again Standby replication relation.
6. method according to claim 3, it is characterised in that the acquisition native database The step of rearmost position, includes:
Obtain the current log file list of the native database;
Since last journal file in the current log file list scan, and from it is described last The rearmost position of the native database is obtained in last event of individual journal file;
If last described event can not be found from last described journal file, scanning it is described last A upper journal file for individual journal file, until finding last described event.
7. a kind of master/slave data storehouse switching device, it is characterised in that described device includes:
Link block, for performing connection native database service operations;
Position module, for receiving to client database transmission to client database current location;
Performing module, if the frequency of failure for the connection native database service operations exceedes default number of times, Then judge that the native database is abnormal, and perform alarm operation or in the native database and the opposite end number According to progress active-standby switch operation between storehouse, or, if the reception working as to client database to client database transmission The frequency of failure of front position exceedes default number of times, then performs alarm operation or in the native database and described To carrying out active-standby switch operation between client database.
8. device according to claim 7, it is characterised in that
The link block, is additionally operable to perform connection native database service operations, timing acquisition native database Current location;
The position module, is additionally operable to receive to client database transmission to client database current location, will be described Client database current location is compared with described for native database current location;
Described device also includes:
Alarm module, for when the native database current location and the difference to client database current location When value is more than default threshold value, alarm operation is performed.
9. device according to claim 8, it is characterised in that
The performing module, it is described to based on client database if it is standby database to be additionally operable to the native database Database, then perform alarm operation, and continue executing with connecting detection operation;If number based on the native database According to storehouse, described is standby database to client database, then parses the journal file of the native database, obtain institute The rearmost position of native database is stated, and active-standby switch operation is performed according to the rearmost position.
10. device according to claim 9, it is characterised in that
The performing module, if the rearmost position for being additionally operable to the primary database is not sky, contrasts the main number According to the rearmost position and the standby database current location in storehouse, wherein, if the standby database current location is equal to The rearmost position of the primary database, then perform automatically switching operation, if the standby database current location is less than Whether the rearmost position of the primary database, then perform the automatically switching operation according to business need decision-making;If The rearmost position of the primary database is sky, then contrasts the current location of the primary database and the standby database Current location, wherein, if the standby database current location is more than or equal to the current location of the primary database, The automatically switching operation is then performed, otherwise, is then grasped according to whether business need decision-making performs described automatically switch Make.
11. device according to claim 10, it is characterised in that
The performing module, if being additionally operable to the user for unspecified persons, performs and specifies directed information to tie up card Operation.
12. device according to claim 9, it is characterised in that
The performing module, is additionally operable to obtain the current log file list of the native database;Work as from described Last journal file in preceding daily record listed files starts scanning, and from last journal file The rearmost position of the native database is obtained in last event;If can not be from last described daily record text Part finds last described event, then scans a upper journal file for last journal file, directly To finding last described event.
CN201610230656.1A 2016-04-13 2016-04-13 Main and standby database switching method and device Active CN107291787B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201610230656.1A CN107291787B (en) 2016-04-13 2016-04-13 Main and standby database switching method and device
PCT/CN2017/080418 WO2017177941A1 (en) 2016-04-13 2017-04-13 Active/standby database switching method and apparatus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610230656.1A CN107291787B (en) 2016-04-13 2016-04-13 Main and standby database switching method and device

Publications (2)

Publication Number Publication Date
CN107291787A true CN107291787A (en) 2017-10-24
CN107291787B CN107291787B (en) 2020-08-28

Family

ID=60042763

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610230656.1A Active CN107291787B (en) 2016-04-13 2016-04-13 Main and standby database switching method and device

Country Status (2)

Country Link
CN (1) CN107291787B (en)
WO (1) WO2017177941A1 (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108833164A (en) * 2018-06-14 2018-11-16 杭州网易再顾科技有限公司 Server control method, device, electronic equipment and storage medium
CN108897641A (en) * 2018-06-21 2018-11-27 武汉达梦数据库有限公司 A kind of log analysis under the active and standby environment of database services real-time synchronization system
CN109144790A (en) * 2018-09-30 2019-01-04 广州鼎甲计算机科技有限公司 The synthesized backup method and device of MySQL database
CN109308242A (en) * 2018-09-06 2019-02-05 上海达梦数据库有限公司 A kind of dynamic monitoring and controlling method, device, equipment and storage medium
CN109857802A (en) * 2018-12-12 2019-06-07 深圳前海微众银行股份有限公司 Daily record data synchronous method, device, equipment and computer readable storage medium
CN109885344A (en) * 2019-02-27 2019-06-14 四川航空股份有限公司 Operating system switching method and device
CN110166524A (en) * 2019-04-12 2019-08-23 陆金所(上海)科技服务有限公司 Switching method, device, equipment and the storage medium of data center
CN111209140A (en) * 2019-12-30 2020-05-29 苏州浪潮智能科技有限公司 Method and device for recovering crash of main and standby dual-node databases
CN111460029A (en) * 2020-03-11 2020-07-28 中移动信息技术有限公司 Data synchronization method and device
CN111653052A (en) * 2020-04-26 2020-09-11 北京三快在线科技有限公司 Cash register system and cash register switching method
CN112069018A (en) * 2020-07-21 2020-12-11 上海瀚银信息技术有限公司 High-availability method and system for database
CN113032477A (en) * 2019-12-24 2021-06-25 中移在线服务有限公司 Long-distance data synchronization method and device based on GTID and computing equipment
CN113761075A (en) * 2020-09-01 2021-12-07 北京沃东天骏信息技术有限公司 Method, device, equipment and computer readable medium for switching databases
CN113830134A (en) * 2021-08-25 2021-12-24 通号城市轨道交通技术有限公司 Vehicle-mounted ATP (automatic train protection) dual-system switching method and logic unit of vehicle-mounted ATP

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111258823A (en) * 2020-01-17 2020-06-09 青梧桐有限责任公司 Method and system for switching master server and slave server
CN112307054B (en) * 2020-11-18 2023-02-28 太原理工大学 Reading and writing method for active and standby servers of double active databases
CN113792340B (en) * 2021-09-09 2023-09-05 烽火通信科技股份有限公司 Method and device for auditing logical logs of database
CN113836160B (en) * 2021-09-28 2024-01-23 上海市大数据股份有限公司 Data stream state monitoring alarm system based on master-slave synchronization
CN115934428B (en) * 2023-01-10 2023-05-23 湖南三湘银行股份有限公司 Main disaster recovery and backup switching method and device of MYSQL database and electronic equipment
CN115941451B (en) * 2023-02-21 2023-05-09 浙江国利信安科技有限公司 Method, apparatus and storage medium for redundant switching in an industrial control network
CN115914418B (en) * 2023-03-09 2023-06-30 北京全路通信信号研究设计院集团有限公司 Railway interface gateway equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1567889A (en) * 2003-06-25 2005-01-19 华为技术有限公司 A method of automatic primary standby equipment switching
US7224956B1 (en) * 2001-06-18 2007-05-29 At & T Corp. Enhanced 911 system for providing witness identification in a wireless communication system
CN102013997A (en) * 2010-11-22 2011-04-13 中兴通讯股份有限公司 Backup method and system for dual-computer data in telecom network management system
CN102194009A (en) * 2011-06-09 2011-09-21 北京新媒传信科技有限公司 Database hosting method and database hosting platform system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102693171B (en) * 2011-08-05 2015-11-18 新奥特(北京)视频技术有限公司 A kind of restoration methods of Message Entry System and system
CN102955851B (en) * 2012-10-30 2016-05-11 北京奇虎科技有限公司 A kind of switching method and apparatus of database

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7224956B1 (en) * 2001-06-18 2007-05-29 At & T Corp. Enhanced 911 system for providing witness identification in a wireless communication system
CN1567889A (en) * 2003-06-25 2005-01-19 华为技术有限公司 A method of automatic primary standby equipment switching
CN102013997A (en) * 2010-11-22 2011-04-13 中兴通讯股份有限公司 Backup method and system for dual-computer data in telecom network management system
CN102194009A (en) * 2011-06-09 2011-09-21 北京新媒传信科技有限公司 Database hosting method and database hosting platform system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王茜等: "高校数据库切换技术研究与实践", 《高校数据库切换技术研究与实践 *

Cited By (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108833164A (en) * 2018-06-14 2018-11-16 杭州网易再顾科技有限公司 Server control method, device, electronic equipment and storage medium
CN108833164B (en) * 2018-06-14 2021-10-08 杭州网易再顾科技有限公司 Server control method, device, electronic equipment and storage medium
CN108897641A (en) * 2018-06-21 2018-11-27 武汉达梦数据库有限公司 A kind of log analysis under the active and standby environment of database services real-time synchronization system
CN108897641B (en) * 2018-06-21 2020-08-18 武汉达梦数据库有限公司 Log analysis service real-time synchronization system under database master-slave environment
CN109308242A (en) * 2018-09-06 2019-02-05 上海达梦数据库有限公司 A kind of dynamic monitoring and controlling method, device, equipment and storage medium
CN109308242B (en) * 2018-09-06 2021-11-19 上海达梦数据库有限公司 Dynamic monitoring method, device, equipment and storage medium
CN109144790A (en) * 2018-09-30 2019-01-04 广州鼎甲计算机科技有限公司 The synthesized backup method and device of MySQL database
CN109857802A (en) * 2018-12-12 2019-06-07 深圳前海微众银行股份有限公司 Daily record data synchronous method, device, equipment and computer readable storage medium
CN109885344A (en) * 2019-02-27 2019-06-14 四川航空股份有限公司 Operating system switching method and device
CN110166524A (en) * 2019-04-12 2019-08-23 陆金所(上海)科技服务有限公司 Switching method, device, equipment and the storage medium of data center
CN113032477A (en) * 2019-12-24 2021-06-25 中移在线服务有限公司 Long-distance data synchronization method and device based on GTID and computing equipment
CN113032477B (en) * 2019-12-24 2023-07-21 中移在线服务有限公司 Long-distance data synchronization method and device based on GTID and computing equipment
CN111209140B (en) * 2019-12-30 2023-01-06 苏州浪潮智能科技有限公司 Method and device for recovering crash of main and standby dual-node databases
CN111209140A (en) * 2019-12-30 2020-05-29 苏州浪潮智能科技有限公司 Method and device for recovering crash of main and standby dual-node databases
CN111460029B (en) * 2020-03-11 2024-04-19 中移动信息技术有限公司 Data synchronization method and device
CN111460029A (en) * 2020-03-11 2020-07-28 中移动信息技术有限公司 Data synchronization method and device
CN111653052A (en) * 2020-04-26 2020-09-11 北京三快在线科技有限公司 Cash register system and cash register switching method
CN111653052B (en) * 2020-04-26 2022-06-21 北京三快在线科技有限公司 Cash register system and cash register switching method
CN112069018A (en) * 2020-07-21 2020-12-11 上海瀚银信息技术有限公司 High-availability method and system for database
CN112069018B (en) * 2020-07-21 2024-05-31 上海瀚银信息技术有限公司 Database high availability method and system
CN113761075A (en) * 2020-09-01 2021-12-07 北京沃东天骏信息技术有限公司 Method, device, equipment and computer readable medium for switching databases
CN113830134A (en) * 2021-08-25 2021-12-24 通号城市轨道交通技术有限公司 Vehicle-mounted ATP (automatic train protection) dual-system switching method and logic unit of vehicle-mounted ATP
CN113830134B (en) * 2021-08-25 2024-03-15 通号城市轨道交通技术有限公司 Vehicle-mounted ATP double-system switching method and logic unit of vehicle-mounted ATP

Also Published As

Publication number Publication date
CN107291787B (en) 2020-08-28
WO2017177941A1 (en) 2017-10-19

Similar Documents

Publication Publication Date Title
CN107291787A (en) Master/slave data storehouse switching method and apparatus
CN110209726B (en) Distributed database cluster system, data synchronization method and storage medium
CN106254094B (en) A kind of method of data synchronization and system
CN108076098B (en) Service processing method and system
CN101826073B (en) Synchronous method, apparatus and system for distributed database
CN101964820B (en) Method and system for keeping data consistency
CN106202075A (en) A kind of method and device of data base's active-standby switch
CN105512171B (en) The method and device of database synchronization
CN101706795A (en) Method for synchronizing data of database in active/standby server
US20130086418A1 (en) Data processing failure recovery method, system and program
CN103699063A (en) Device and method for acquiring off-line data of MES (Manufacturing Execution Method) system
CN112506702A (en) Data center disaster tolerance method, device, equipment and storage medium
CN111913933B (en) Power grid historical data management method and system based on unified support platform
CN114500554A (en) Internet of things system management method
CN116185697B (en) Container cluster management method, device and system, electronic equipment and storage medium
CN105323271B (en) Cloud computing system and processing method and device thereof
CN111404737B (en) Disaster recovery processing method and related device
CN115017235B (en) Data synchronization method, electronic device and storage medium
CN115587147A (en) Data processing method and system
CN115878721A (en) Data synchronization method, device, terminal and computer readable storage medium
CN113127435A (en) Intelligent synchronization method and system for files of main and standby systems
CN117827544B (en) Hot backup system, method, electronic device and storage medium
CN111262717B (en) Method and device for recovering data synchronization abnormity in distributed network
CN111143280B (en) Data scheduling method, system, device and storage medium
CN115391463A (en) Data synchronization method and device and server cluster

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
CB03 Change of inventor or designer information

Inventor after: Zhang Lingdong

Inventor after: Sui Jian

Inventor after: Huang Xinjuan

Inventor after: Liu Wentao

Inventor after: Deng Qiong

Inventor after: Chen Jianfeng

Inventor before: Zhang Lingdong

Inventor before: Sui Jian

Inventor before: Huang Xinjuan

CB03 Change of inventor or designer information
TA01 Transfer of patent application right

Effective date of registration: 20180112

Address after: 518057 Nanshan District Guangdong high tech Industrial Park, South Road, science and technology, ZTE building, Ministry of Justice

Applicant after: ZTE Corporation

Applicant after: China Citic Bank Co., Ltd.

Address before: 518057 Nanshan District Guangdong high tech Industrial Park, South Road, science and technology, ZTE building, Ministry of Justice

Applicant before: ZTE Corporation

TA01 Transfer of patent application right
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant