Mysql strange land synchronously strengthens the system that realizes and the implementation method of fault-tolerance
Technical field
The present invention relates to Mysql database, particularly a kind of Mysql strange land synchronously strengthens the system that realizes and the implementation method of fault-tolerance.
Background technology
Mysql is a kind of database server software that Master/Slave disposes of can supporting, but when strange land network connection state instability, the Position of database can be caused to misplace, slave data are different with master, and consume the Bin-log file of a large amount of disk space store M ysql, cause system unavailable.
Due to by the restriction of different operators, China Netcom, telecommunication user data base consistency(-tance), stability requirement when using network application is higher, and existing best solution is exactly strange land vlan special line, carrys out Deterministic service device and so on data interaction.But machine room, bandwidth cost is very expensive, is not suitable for small-sized Internet firm and uses.
Summary of the invention
For above-mentioned deficiency of the prior art, a kind of Mysql strange land is the object of the present invention is to provide synchronously to strengthen the system that realizes and the implementation method of fault-tolerance, it can realize consistance and the stability of strange land data with less cost, can be applicable to small-sized Internet firm.
In order to achieve the above object, the present invention is achieved by the following technical solutions.
What Mysql strange land synchronously strengthened fault-tolerance realizes system, and this system comprises: master server, queue server and client;
Master server, queue server and client adopt the independent operation mode of Mysql; Described queue server adopts message queue technology, and queue server and client adopt RESTful http protocol mode to dock.
Mysql strange land synchronously strengthens the implementation method of fault-tolerance, it is characterized in that, the method comprises following steps:
(1) the CRUD information of master server acquisition tasks data, and be stored into queue server;
The database manipulation order that database manipulation relates to by master server, is stored into queue server according to time order and function, forms command queue, and command queue adopts message queue mode to store;
(2) queue server adopts message queue technology, is distributed to each client;
The database command message queue of the formation in step (1) is adopted function call-back manner by queue server, be distributed to each client one by one, queue server and client adopt RESTful http protocol mode to dock, if client executing success, can notify master server state, carry out the execution of next command again, if unsuccessful, then do not destroy task, all data of rollback;
(3) client obtains CRUD data and performs to the machine from queue server;
Queue server controls the abnormal information of all clients, quick rollback abnormal data, ensures that the data of all client databases are definitely consistent.
Further: in above-mentioned implementation method, master server is transferred to queuing data after client port performs, if there is abnormal appearance, can clears up queuing message, return exception, if client operation success, then return queuing message and be written to master server.
The present invention has outstanding substantive distinguishing features and significant effect compared to existing technology:
In the present invention, the database manipulation order (SQL) that database manipulation relates to by local master server (master), is stored into queue server according to time order and function, forms command queue, command queue adopts message queue mode to store, and effectiveness of performance is very efficient;
In the present invention, the database command message queue formed is adopted " function call-back manner " by queue server, be distributed to each client (SLAVE) one by one, queue server and client adopt RESTful http protocol mode to dock, if client executing success, can notify master server state, carry out the execution of next command again, if unsuccessful, then do not destroy task, the all data of rollback, so both ensure that the consistance of each client data, also ensure that the security of data;
In the present invention, queue server can control the abnormal information of all clients, quick rollback abnormal data, ensures that the data of all client databases are definitely consistent, what adopt due to each client data is independent operation mode, so stability is greatly improved.
Accompanying drawing explanation
Below in conjunction with the drawings and specific embodiments, the present invention is described in further details.
Fig. 1 is system architecture schematic diagram of the present invention;
Fig. 2 is that implementation method of the present invention performs schematic flow sheet.
Embodiment
The present invention realizes structure and realization flow is described as embodiment using concrete.
As shown in Figure 1, what Mysql strange land synchronously strengthened fault-tolerance realizes system, and this system comprises: master server, queue server and client;
Master server, queue server and client adopt the independent operation mode of Mysql; Described queue server adopts message queue technology, and queue server and client adopt RESTful http protocol mode to dock.
As shown in Figure 2, Mysql strange land synchronously strengthens the implementation method of fault-tolerance, comprises following steps:
(1) the CRUD information of master server image data, and be stored into queue server;
The database manipulation order (SQL) that database manipulation relates to by local master server (master), queue server is stored into according to time order and function, form command queue, command queue adopts message queue mode to store, effectiveness of performance is very efficient, and traditional Mysql (bin-log) mode adopts text log mode, very frequent to the IO read-write of disk, cause performance very low.
(2) queue server adopts message queue technology, is distributed to each client;
The database command message queue of the formation in step (1) is adopted " function call-back manner " by queue server, be distributed to each client (SLAVE) one by one, queue server and client adopt RESTful http protocol mode to dock, if client executing success, can notify master server state, carry out the execution of next command again, if unsuccessful, then do not destroy task, the all data of rollback, so both ensure that the consistance of each client data, also ensure that the security of data.And traditional communication modes socket from master to slave agreement be inconvenient to debug, and exception catching is simple, does not also have rollback mechanism, client often can stop accepting synchronous, or receives incorrect data.
(3) client obtains CRUD data and performs to the machine from queue server;
Queue server can control the abnormal information of all clients, quick rollback abnormal data, and the data ensureing all client databases are definitely consistent, and what adopt due to each client data is independent operation mode, so stability is greatly improved.
Application case: micro-trade is led to, one-stop foreign trade band operation platform, it is an overseas b2b platform of serving Chinese foreign trade enterprise, this platform adopts SAAS mode to rent to foreign trade enterprise, for client sets up overseas multilingual b2b web station system, domestic foreign trade enterprise completes the issue work of all product data at middle domestic server, overseas foreign trade client is by overseas disk-based web site access b2b website data, and send inquiry to domestic foreign trade enterprise, current enterprise number 2000, product information 3000W, SEO keyword 200,000,000.There is following obviously problem in this case: 1. big data quantity strange land is synchronous; 2. network is obstructed both at home and abroad, and unstable, packet loss is serious; 3. data information coherence request is high, can not occur the situation that multiple spot is inconsistent.Whole project adopts the present invention, the storage of domestic data this locality, accelerate the efficiency that domestic enterprise's business datum is safeguarded, incremental data order (SQL) is written to message queue simultaneously, be transferred to overseas each server by HTTP mode to perform, and feedback readjustment result, if there is legacy, then rollback data.Thus ensure that the stability of system, fault-tolerance, high availability.
Preferably, as shown in Figure 2, after master server is transferred to client port execution queuing data, if there is abnormal appearance, can queuing message be cleared up, return exception, if client operation success, return queuing message again and be written to master server, such write sequence can ensure all customer inquiries to data be all consistent.
By reference to the accompanying drawings the preferred embodiment for the present invention is explained in detail above, but the invention is not restricted to above-mentioned embodiment, in the ken that those of ordinary skill in the art possess, can also make a variety of changes under the prerequisite not departing from present inventive concept.
Those of ordinary skill in the art do not depart from the spirit and scope of the present invention can make other changes many and remodeling.Should be appreciated that and the invention is not restricted to specific embodiment, scope of the present invention is defined by the following claims.