CN105956139A - Method for synchronizing database in two machines - Google Patents
Method for synchronizing database in two machines Download PDFInfo
- Publication number
- CN105956139A CN105956139A CN201610312656.6A CN201610312656A CN105956139A CN 105956139 A CN105956139 A CN 105956139A CN 201610312656 A CN201610312656 A CN 201610312656A CN 105956139 A CN105956139 A CN 105956139A
- Authority
- CN
- China
- Prior art keywords
- database
- data
- shipper
- data base
- request
- 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.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/07—Responding to the occurrence of a fault, e.g. fault tolerance
- G06F11/14—Error detection or correction of the data by redundancy in operation
- G06F11/1402—Saving, restoring, recovering or retrying
- G06F11/1446—Point-in-time backing up or restoration of persistent data
- G06F11/1448—Management of the data involved in backup or backup restore
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
- G06F16/2365—Ensuring data consistency and integrity
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, 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)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Quality & Reliability (AREA)
- Computing Systems (AREA)
- Computer Security & Cryptography (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The present invention discloses a method for synchronizing a database in two machines. The method includes the following steps of providing an external interface for an application thread to perform a database operation request; creating a master and a slave database service execution thread; and creating a database two-machine synchronization service. The method can be applied to different mainstream databases, so as to facilitate execution of operations like database data migration; SQL data blocks are simultaneously distributed to the master and the slave database service execution threads and data is recovered when a database fault is eliminated, so that consistency and integrity of data of the master database and the slave database are ensured.
Description
Technical field
The present invention relates to a kind of method that data base's two-shipper synchronizes, belong to communication technical field.
Background technology
In order to ensure system run all right, general employing Double Data storehouse system carries out data access.Double Data storehouse needs to solve master-slave database data synchronization problems.Two-shipper can be reached by database programming to synchronize.If MDL and data syn-chronization real-time is had higher requirement from data base, can all build trigger in two storehouses, the most currently in which storehouse occur data update can real-time synchronization data to offside data base;If the highest to the requirement of real-time of data syn-chronization, then can by customization storing process by the way of (add timestamp to the tables of data of two data bases of principal and subordinate or update mark) Timing Synchronization data;Can also be in conjunction with both the above mode, by adding renewal attribute field to the tables of data of two data bases, be main to meet the requirement of real-time in the first manner, be auxiliary to make up trigger that may be present and perform to update unsuccessful situation in the second.
Current conventional Sybase mainly has Oracle, SQL Server, MySQL, Jin Cang, reaches dream etc..The implementation of every kind of database programming is had nothing in common with each other, if using database programming mode to realize the synchronization of data base, then need when running into data migration between disparate databases to write the script adapting to disparate databases, if now a database script is changed, it is necessary to other database scripts of synchronous vacations.When carrying out data migration between same data base, it is also desirable to transplant script accordingly, considerably increase the complexity of data-base transplantation.If have a machine to depart from network due to fault simultaneously, unenforced database request during fault can not being recovered when fault recovery, thus cause two database datas inconsistent.
Summary of the invention
The technical problem to be solved is the defect overcoming prior art, there is provided a kind of method that data base's two-shipper synchronizes, with data integrity issues when master-slave database Data Consistency during effectively solution data base's duplex running and data base's fault recovery.
For solving above-mentioned technical problem, the present invention provides a kind of method that data base's two-shipper synchronizes, it is characterised in that comprise the following steps:
1) application thread is provided to carry out the external interface of database manipulation request;
2) create master and slave database service and perform thread;
3) data base's two-shipper synchronous service is created.
In aforesaid step 1), application thread carries out the external interface of database manipulation request, including following three kinds of optional modes: one is the complete SQL statement arranging database manipulation;Two is SQL statement and the serial data being provided with placeholder;Three is to be separately provided the SQL statement with placeholder and arrange data to be operated.
Aforesaid serial data has a plurality of, and every data string has multiple field;Separate with special symbol between every data string, wall scroll serial data separates with different special symbols between field;Described special symbol includes: "@", " # ", ";" and ", ".
Aforesaid database manipulation request be to be constituted with block structure, block structure comprises SQL statement to be performed and data, block structure comprises a semaphore carrying out simultaneously operating simultaneously, by this semaphore control database ask time simultaneously operating.
Aforesaid step 2) in, database service performs thread and there are two kinds of abnormal conditions when performing database manipulation request: one is due to database server fault, causes SQL statement normally not perform;Another kind is owing to SQL statement grammer is wrong, causes SQL statement to perform exception.
Aforesaid database server failure exception refers to; data base connect acquisition less than; need that database manipulation request is converted into character string preservation and become local file; after the connection of pending data storehouse can normally obtain; the database manipulation request of reading and saving from local file, then carry out database request execution.
The wrong exception caused of aforesaid SQL statement grammer refers to, application layer constructs the SQL statement that can not correctly perform, and needs this request of data write file and is saved under mistake SQL catalogue, and returns mistake and perform mark.
In aforesaid step 3), create data base's two-shipper synchronous service, including:
The database manipulation received request is distributed to master and slave database service and performs thread;
Block the application thread currently carrying out database manipulation request;
Timing is inquired about master and slave database service and is performed the execution state of thread, wakes up database manipulation request up and is finished or returns the application thread of time-out.
The beneficial effect that the present invention is reached:
(1) present invention does not relies on data base itself when data base's two-shipper synchronizes, and can be adaptive to different Sybases, when performing the operations such as database data migration, it is not necessary to data base carries out the operation of complexity;
(2) present invention is by simultaneously to master-slave database service execution thread distribution SQL data block with realize data when database failure recovers and recover, it is ensured that the concordance of data and integrity during the synchronization of data base's two-shipper.
Accompanying drawing explanation
Fig. 1 is the flow chart of the method for data base's two-shipper synchronization of the present invention;
Fig. 2 is the theory diagram of the method for data base's two-shipper synchronization of the present invention;
Fig. 3 is the schematic flow sheet during database service execution thread process abnormal conditions of the present invention.
Detailed description of the invention
The invention will be further described below in conjunction with the accompanying drawings.Following example are only used for clearly illustrating technical scheme, and can not limit the scope of the invention with this.
As it is shown in figure 1, the method that data base's two-shipper of the present invention synchronizes comprises the following steps:
Step 101: provide application thread to carry out the external interface of database manipulation request;
Application thread carries out the external interface of database manipulation request, including following three kinds of optional modes: one is the complete SQL statement arranging database manipulation;Two is SQL statement and the serial data being provided with placeholder;Three is to be separately provided the SQL statement with placeholder and arrange data to be operated.Wherein, serial data can have a plurality of, and every data string can have multiple field.Separating with special symbol between every data string, in wall scroll serial data, each field separates with different special symbols.Special symbol specifically include that "@", " # ", ";" and ", ".
Above-mentioned database manipulation request be to be constituted with block structure, block structure comprises SQL statement to be performed and data, block structure comprises a semaphore that can carry out simultaneously operating simultaneously, by this semaphore control database ask time simultaneously operating.
Step 102: create master and slave database service and perform thread;
Create master and slave database service simultaneously and perform thread.Database service performs thread and mainly includes two kinds of abnormal conditions when performing database manipulation request, and one is due to database server fault, causes SQL statement normally not perform;Another kind is owing to SQL statement grammer is wrong, causes SQL statement to perform exception.Wherein, database server failure exception specifically includes: data base connect acquisition less than, need by database manipulation request be converted into character string preserve become local file;After the connection of pending data storehouse can normally obtain, the database manipulation request of reading and saving from local file, then carry out database request execution.The wrong exception caused of SQL statement grammer specifically includes: application layer constructs the SQL statement that can not correctly perform, and needs this request of data write file and is saved under mistake SQL catalogue, and returns mistake and perform mark.
Step 103: create data base's two-shipper synchronous service.
This step specifically includes: the database manipulation received request is distributed to master and slave database service and performs thread;Block the application thread currently carrying out database manipulation request;Timing is inquired about master and slave database service and is performed the execution state of thread, wakes up database manipulation request up and is finished or returns the application thread of time-out.
The theory diagram of the method that data base's two-shipper of the present invention synchronizes, as in figure 2 it is shown,
When application thread starts a database manipulation request, construct a SQL data block, call data base's external interface function exec (), SQL data block is cloned two parts.
The SQL data block of clone is respectively added to master and slave data base SQL to be sent data block queue by data base's two-shipper synchronous service, when being asked by database manipulation, the SQL data block of transmission is added to and is not returned SQL data block Map simultaneously, starts thread block function data block within and currently carries out the application thread of database manipulation request with obstruction.
Master and slave database service performs thread and reads unenforced SQL data block from master and slave data base SQL to be sent data block queue respectively, performs successively, the SQL data block being finished is added to SQL data block and is finished queue.
The timing inquiry thread timing of execution state is read SQL data block and is finished queue, and wakes up the application thread that the SQL data block not returned in SQL data block Map is corresponding up.Additionally perform state timing inquiry thread timing detection and do not return the timeout mode of the SQL data block in SQL data block Map, return the application thread that the SQL data block having timed, out is corresponding.
In sum, in the present invention, by simultaneously to master and slave database server distribution SQL data block with realize data when database failure recovers and recover, it is ensured that the concordance of data and integrity during the synchronization of data base's two-shipper.Do not rely on data base itself when data base's two-shipper synchronizes simultaneously, different Sybases can be adaptive to, when performing the operations such as database data migration, it is not necessary to carry out the database manipulation of complexity.
Database service of the present invention perform thread process abnormal conditions time flow process as it is shown on figure 3, database service of the present invention perform thread use steps of processing abnormal conditions:
Step 1: database service performs thread timing and reads unenforced abnormal SQL data block file from local abnormal SQL data block catalogue in abnormal SQL data block queue, performs abnormal SQL data block according to following sub-step the most successively,
Step 1.1: connect if able to get data base and run succeeded, then delete this record from abnormal SQL data block queue, and single SQL data block has processed;
Step 1.2: if able to normally get data base's connection but perform failure, then be saved as this SQL data block file and be saved under local mistake SQL data block catalogue, and delete this record from abnormal SQL data block queue, and single SQL data block has processed;
Step 1.3: connect if data base can not be got, does not the most process the SQL data block in abnormal SQL data block queue.
Step 2: timing is saved as file the SQL data block in abnormal SQL data block queue and is saved under abnormal SQL data block catalogue, and empties the content in abnormal SQL data block queue.
The above is only the preferred embodiment of the present invention; it should be pointed out that, for those skilled in the art, on the premise of without departing from the technology of the present invention principle; can also make some improvement and deformation, these improve and deformation also should be regarded as protection scope of the present invention.
Claims (8)
1. the method that data base's two-shipper synchronizes, it is characterised in that comprise the following steps:
1) application thread is provided to carry out the external interface of database manipulation request;
2) create master and slave database service and perform thread;
3) data base's two-shipper synchronous service is created.
The method that a kind of data base's two-shipper the most according to claim 1 synchronizes, it is characterized in that, in described step 1), application thread carries out the external interface of database manipulation request, including following three kinds of optional modes: one is the complete SQL statement arranging database manipulation;Two is SQL statement and the serial data being provided with placeholder;Three is to be separately provided the SQL statement with placeholder and arrange data to be operated.
The method that a kind of data base's two-shipper the most according to claim 2 synchronizes, it is characterised in that described serial data has a plurality of, and every data string has multiple field;Separate with special symbol between every data string, wall scroll serial data separates with different special symbols between field;Described special symbol includes: "@", " # ", ";" and ", ".
The method that a kind of data base's two-shipper the most according to claim 2 synchronizes, it is characterized in that, the request of described database manipulation is to be constituted with block structure, block structure comprises SQL statement to be performed and data, block structure comprises a semaphore carrying out simultaneously operating simultaneously, by this semaphore control database request time simultaneously operating.
The method that a kind of data base's two-shipper the most according to claim 1 synchronizes, it is characterized in that, described step 2) in, database service performs thread and there are two kinds of abnormal conditions when performing database manipulation request: one is due to database server fault, causes SQL statement normally not perform;Another kind is owing to SQL statement grammer is wrong, causes SQL statement to perform exception.
The method that a kind of data base's two-shipper the most according to claim 5 synchronizes; it is characterized in that; described database server failure exception refers to; data base connect acquisition less than; need that database manipulation request is converted into character string preservation and become local file; after the connection of pending data storehouse can normally obtain, the database manipulation request of reading and saving from local file, then carry out database request execution.
The method that a kind of data base's two-shipper the most according to claim 5 synchronizes, it is characterized in that, the wrong exception caused of described SQL statement grammer refers to, application layer constructs the SQL statement that can not correctly perform, need by this request of data write file and be saved in mistake SQL catalogue under, and return mistake perform mark.
The method that a kind of data base's two-shipper the most according to claim 1 synchronizes, it is characterised in that in described step 3), creates data base's two-shipper synchronous service, including:
The database manipulation received request is distributed to master and slave database service and performs thread;
Block the application thread currently carrying out database manipulation request;
Timing is inquired about master and slave database service and is performed the execution state of thread, wakes up database manipulation request up and is finished or returns the application thread of time-out.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610312656.6A CN105956139A (en) | 2016-05-12 | 2016-05-12 | Method for synchronizing database in two machines |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610312656.6A CN105956139A (en) | 2016-05-12 | 2016-05-12 | Method for synchronizing database in two machines |
Publications (1)
Publication Number | Publication Date |
---|---|
CN105956139A true CN105956139A (en) | 2016-09-21 |
Family
ID=56912495
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610312656.6A Pending CN105956139A (en) | 2016-05-12 | 2016-05-12 | Method for synchronizing database in two machines |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105956139A (en) |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106657376A (en) * | 2017-01-04 | 2017-05-10 | 泰康保险集团股份有限公司 | Data synchronization processing method and device |
CN108038163A (en) * | 2017-12-06 | 2018-05-15 | 交控科技股份有限公司 | Standby control center database synchronous system |
CN110019500A (en) * | 2017-08-21 | 2019-07-16 | 东软集团股份有限公司 | A kind of copy group method for monitoring state, device, equipment and storage medium |
CN110825767A (en) * | 2019-11-15 | 2020-02-21 | 江苏满运软件科技有限公司 | Data query method, platform, equipment and storage medium |
CN112650807A (en) * | 2021-01-04 | 2021-04-13 | 成都知道创宇信息技术有限公司 | Data storage management method and device, electronic equipment and readable storage medium |
CN113918384A (en) * | 2021-10-12 | 2022-01-11 | 深圳市铭镭激光设备有限公司 | Data saving method, device, equipment and storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7290015B1 (en) * | 2003-10-02 | 2007-10-30 | Progress Software Corporation | High availability via data services |
CN102013997A (en) * | 2010-11-22 | 2011-04-13 | 中兴通讯股份有限公司 | Backup method and system for dual-computer data in telecom network management system |
CN102063502A (en) * | 2011-01-06 | 2011-05-18 | 天津神舟通用数据技术有限公司 | Method for realizing synchronization of data in heterogeneous database |
-
2016
- 2016-05-12 CN CN201610312656.6A patent/CN105956139A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7290015B1 (en) * | 2003-10-02 | 2007-10-30 | Progress Software Corporation | High availability via data services |
CN102013997A (en) * | 2010-11-22 | 2011-04-13 | 中兴通讯股份有限公司 | Backup method and system for dual-computer data in telecom network management system |
CN102063502A (en) * | 2011-01-06 | 2011-05-18 | 天津神舟通用数据技术有限公司 | Method for realizing synchronization of data in heterogeneous database |
Non-Patent Citations (1)
Title |
---|
薛竹飙: "实时内存数据库关键技术的研究与实现", 《中国优秀硕士学位论文全文数据库 信息科技辑》 * |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106657376A (en) * | 2017-01-04 | 2017-05-10 | 泰康保险集团股份有限公司 | Data synchronization processing method and device |
CN106657376B (en) * | 2017-01-04 | 2020-08-28 | 泰康保险集团股份有限公司 | Data synchronization processing method and device |
CN110019500A (en) * | 2017-08-21 | 2019-07-16 | 东软集团股份有限公司 | A kind of copy group method for monitoring state, device, equipment and storage medium |
CN108038163A (en) * | 2017-12-06 | 2018-05-15 | 交控科技股份有限公司 | Standby control center database synchronous system |
CN108038163B (en) * | 2017-12-06 | 2020-07-31 | 交控科技股份有限公司 | Master and backup control center database synchronization system |
CN110825767A (en) * | 2019-11-15 | 2020-02-21 | 江苏满运软件科技有限公司 | Data query method, platform, equipment and storage medium |
CN112650807A (en) * | 2021-01-04 | 2021-04-13 | 成都知道创宇信息技术有限公司 | Data storage management method and device, electronic equipment and readable storage medium |
CN113918384A (en) * | 2021-10-12 | 2022-01-11 | 深圳市铭镭激光设备有限公司 | Data saving method, device, equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105956139A (en) | Method for synchronizing database in two machines | |
CN110209726B (en) | Distributed database cluster system, data synchronization method and storage medium | |
CN106777225B (en) | Data migration method and system | |
CN106776121B (en) | Data disaster recovery device, system and method | |
CN107016087B (en) | Hierarchical database high-availability system based on sentry's model | |
US9542468B2 (en) | Database management system and method for controlling synchronization between databases | |
CN102693324B (en) | Distributed database synchronization system, synchronization method and node management method | |
CN103500229A (en) | Database synchronization method and database system | |
CN102681917B (en) | A kind of operating system and restorative procedure thereof | |
CN101316184B (en) | Disaster tolerance switching method, system and device | |
CN102622427A (en) | Method and system for read-write splitting database | |
CN104679614B (en) | A kind of Database Disaster Backup/Recover | |
CN106301938A (en) | A kind of high availability and the data base cluster system of strong consistency and node administration method thereof | |
CN103970833A (en) | Method for achieving two-way synchronous data circulation in heterogeneous database synchronizing system based on logs | |
CN104679841A (en) | Consumption terminal data flow copying method and system | |
CN109710586B (en) | A kind of clustered node configuration file synchronous method and device | |
CN105955836A (en) | Cold-hot backup automatic walkthrough multifunction system | |
CN106156318A (en) | A kind of system and method realizing multinode data base's High Availabitity | |
CN104021200A (en) | Data synchronizing method and device of database | |
CN102916974A (en) | Cluster configuration updating method | |
CN115794499B (en) | Method and system for dual-activity replication data among distributed block storage clusters | |
CN108667929A (en) | Method for synchronizing data to elastic search based on HBase coprocessor | |
CN106855869B (en) | Method, device and system for realizing high availability of database | |
CN103019626A (en) | Storage system, method and device for controlling cluster metadata | |
CN106547584A (en) | A kind of backing method and device of application program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20160921 |
|
RJ01 | Rejection of invention patent application after publication |