A kind of data processing system, method, router and from database
Technical field
This specification is related to database field, in particular to a kind of data processing system, method, router and from data
Library.
Background technique
More and more to the access request of database with the continuous development of Internet technology, access frequency is also increasingly
It is high.In order to improve the service ability of database, usually primary database is equipped with multiple from database, provides read-write point for client
From, read load balancing service, mitigate the access pressure of primary database.
The leader follower replication function of being provided between master-slave database by database bottom keeps the consistency of data, but main
There is certain delay from the synchronization between database.Many database access requests have certain want to master-slave database delay
It asks.In the prior art, for the processing of database access request, a middleware is usually provided and passes through monitor component timing acquisition
Delayed data and caching between master-slave database, when database access request arrives, middleware can compare the master of current cache
The delay received from delay and user generates routing decision to the database access request of user using principal and subordinate's delay of caching,
The access request is sent to database still from database by selection.
In the read and write abruption scheme of database, the delay situation between master-slave database is to influence read and write abruption strategy
One important judgment basis.Existing database middleware is easy using the detection of timing and principal and subordinate's time-delay method of caching
There is the principal and subordinate cached delay and actual principal and subordinate delay is inconsistent, leads to the technical problem of principal and subordinate's delay judgement inaccuracy, into
And occur principal and subordinate's data it is inconsistent cause access fail.
Summary of the invention
This specification embodiment provides a kind of data processing system, method, router and from database, existing for solving
In technology between master-slave database principal and subordinate's delay judgement inaccuracy technical problem, improve principal and subordinate's delay judgement accuracy.
In a first aspect, this specification embodiment provides a kind of data processing system, the system comprises: router and from number
According to library;
The router, for receiving and judging the type of database access request;If the database access request
Type is read request, and delay threshold and the database access request are encapsulated into database message;By the database report
It is corresponding described from database that text is sent to primary database;
It is described to judge described between database and primary database from database for receiving the database message
Whether current delay times are within the scope of the delay threshold;According to the current delay times and the delay threshold range
Judging result responds the database access request.
Optionally, it is described to be used for from database: if the current delay times not within the scope of the delay threshold, respond
The database access request handles the database access request.
Optionally, it is described to be also used to from database: if the current delay times not within the scope of the delay threshold, are rung
It answers the database access request generation error message and is sent to the router;
The router is also used to: being received the error message, is responded the database access request and be based on the mistake
The database access request is retransmitted to the primary database by message.
Optionally, it is described to be also used to from database: if the current delay times not within the scope of the delay threshold, are rung
It answers the database access request that the database access request is forwarded to the primary database, passes through the primary database pair
The database access request is handled.
Optionally, the router is also used to: if the type of the database access request is write request, by the data
Library access request is sent to the primary database;
The primary database, for receiving the database access request and being handled.
Second aspect, this specification embodiment provide a kind of data processing method, which comprises
Judge the type of database access request;
If the type of the database access request is read request, delay threshold and the database access request are encapsulated
Into database message;
It is corresponding from database that the database message is sent to primary database, so that described be based on delay from database
Threshold value and the current delay times between database and the primary database, respond the database access request.
Optionally, the method also includes: if the type of the database access request be write request, by the database
Access request is sent to the primary database.
Optionally, the method also includes:
It receives described from the database feedback message that library access request is fed back based on the data;
Judge whether the feedback message is error message;
If the feedback message is error message, the database access request is forwarded to the primary database, so that
The primary database handles the database access request.
The third aspect, this specification embodiment provide a kind of data processing method, which comprises
The database message received from connection is parsed, and delay threshold and database access request are obtained;
Whether the judgement current delay times between database and primary database are within the scope of the delay threshold;
According to the judging result of the current delay times and the delay threshold range, responds the database access and ask
It asks.
Optionally, the judging result according to the current delay times and the delay threshold range, described in response
Database access request, comprising:
If the current delay times within the scope of the delay threshold, respond the database access request to the number
It is handled according to library access request.
Optionally, the judging result according to the current delay times and the delay threshold range, described in response
Database access request, comprising:
If the current delay times, not within the scope of the delay threshold, generation error message is simultaneously sent to router,
So that the router, which is based on the error message, is retransmitted to the primary database for the database access request;Alternatively,
If the current delay times are forwarded to institute not within the scope of the delay threshold, by the database access request
Primary database is stated, the database access request is handled by the primary database.
Fourth aspect, this specification embodiment provide a kind of router, comprising:
Judging unit, for judging the type of database access request;
Encapsulation unit, for the type in the database access request be read request when, by delay threshold and the number
It is encapsulated into database message according to library access request;
Transmission unit, it is corresponding from database for the database message to be sent to primary database so that it is described from
Database responds the data based on delay threshold and the current delay times between database and the primary database
Library access request.
Optionally, the transmission unit is also used to:
When the type of the database access request is write request, the database access request is sent to the master
Database.
Optionally, further includes: receiving unit, for receiving, described from database, library access request is fed back based on the data
Feedback message;
The judging unit is also used to: judging whether the feedback message is error message;
The transmission unit is also used to: when the feedback message is error message, the database access request being turned
It is sent to the primary database, so that the primary database handles the database access request.
5th aspect, this specification embodiment provide a kind of from database, comprising:
Parsing module obtains delay threshold and database access is asked for parsing to the database message received
It asks;
Judgment module, for judging whether the current delay times between database and primary database prolong described
When threshold range in;
Processing module responds institute for the judging result according to the current delay times and the delay threshold range
State database access request.
Optionally, the processing module is used for: if the current delay times within the scope of the delay threshold, respond institute
Database access request is stated to handle the database access request.
It is optionally, described from database further include:
First sending module is used for the generation error when the current delay times are not within the scope of the delay threshold
Message is simultaneously sent to router, so that the router, which is based on the error message, is retransmitted to institute for the database access request
State primary database.
It is optionally, described from database further include:
Second sending module is used for when the current delay times are not within the scope of the delay threshold, by the number
It is forwarded to the primary database according to library access request, the database access request is handled by the primary database.
6th aspect, this specification embodiment provide a kind of computer readable storage medium, are stored thereon with computer journey
Sequence, which is characterized in that the program performs the steps of when being executed by processor
Judge the type of database access request;
If the type of the database access request is read request, delay threshold and the database access request are encapsulated
Into database message;
It is corresponding from database that the database message is sent to primary database, so that described be based on delay from database
Threshold value and the current delay times between database and the primary database, respond the database access request.
7th aspect, this specification embodiment provide a kind of computer readable storage medium, are stored thereon with computer journey
Sequence, which is characterized in that the program performs the steps of when being executed by processor
The database message received from connection is parsed, and delay threshold and database access request are obtained;
Whether the judgement current delay times between database and primary database are within the scope of the delay threshold;
According to the judging result of the current delay times and the delay threshold range, responds the database access and ask
It asks.
Eighth aspect, this specification embodiment provide a kind of electronic equipment, include memory and one or one
Above program, one of them perhaps more than one program be stored in memory and be configured to by one or one with
It includes the instruction for performing the following operation that upper processor, which executes the one or more programs:
Judge the type of database access request;
If the type of the database access request is read request, delay threshold and the database access request are encapsulated
Into database message;
It is corresponding from database that the database message is sent to primary database, so that described be based on delay from database
Threshold value and the current delay times between database and the primary database, respond the database access request.
9th aspect, this specification embodiment provide a kind of electronic equipment, include memory and one or one
Above program, one of them perhaps more than one program be stored in memory and be configured to by one or one with
It includes the instruction for performing the following operation that upper processor, which executes the one or more programs:
The database message received is parsed, delay threshold and database access request are obtained;
Whether the judgement current delay times between database and primary database are within the scope of the delay threshold;
According to the judging result of the current delay times and the delay threshold range, responds the database access and ask
It asks.
Said one or multiple technical solutions in this specification embodiment, at least have the following technical effect that
This specification embodiment provides a kind of data processing system, is received by router and judges database access request
Type;If the type of database access request is read request, delay threshold and database access request are encapsulated into database
In message and to be sent to primary database corresponding from database;By being judged between database and primary database from database
Current delay times whether within the scope of the delay threshold in database message;According to current delay times and delay threshold model
The judging result enclosed, response database access request.By judging the delay between master-slave database from database, avoid
Between part monitoring delay, can accurately obtain the actual delay time of master-slave database, solve principal and subordinate's number in the prior art
According to the technical problem of principal and subordinate's delay judgement inaccuracy between library, the accuracy of principal and subordinate's delay judgement is improved.
Detailed description of the invention
In order to illustrate more clearly of the technical solution in this specification embodiment, embodiment or the prior art will be retouched below
Attached drawing needed in stating is briefly described, it should be apparent that, the accompanying drawings in the following description is the one of this specification
A little embodiments for those of ordinary skill in the art without any creative labor, can also be according to this
A little attached drawings obtain other attached drawings.
Fig. 1 a is a kind of schematic diagram for data processing system that this specification embodiment provides;
Fig. 1 b is a kind of flow chart for data processing method that this specification embodiment provides;
Fig. 2 is a kind of flow chart of the data processing method that provides of this specification embodiment in router side;
Fig. 3 is a kind of data processing method for providing of this specification embodiment in the flow chart from database side;
Fig. 4 is a kind of schematic diagram for router that this specification embodiment provides;
Fig. 5 is a kind of schematic diagram from database that this specification embodiment provides;
Fig. 6 is the schematic diagram for a kind of electronic equipment that this specification embodiment provides.
Specific embodiment
To keep the purposes, technical schemes and advantages of this specification embodiment clearer, below in conjunction with this specification reality
The attached drawing in example is applied, the technical solution in this specification embodiment is clearly and completely described, it is clear that described reality
Applying example is this specification a part of the embodiment, instead of all the embodiments.The embodiment of base in this manual, this field are general
Logical technical staff every other embodiment obtained without creative efforts belongs to this specification protection
Range.
A kind of data processing system, method, router and from database are provided in this specification embodiment, it is existing for solving
There is the technical problem of principal and subordinate's delay judgement inaccuracy in technology between master-slave database, improves the accurate of principal and subordinate's delay judgement
Property.
With reference to the accompanying drawing to the main realization principle of this specification embodiment technical solution, specific embodiment and its right
The beneficial effect that should be able to reach is explained in detail.
Fig. 1 a is please referred to, this specification embodiment provides a kind of data processing system, comprising: router 10, primary database
20, from database 30.Router 10 receives the database access request of user, and database access request is forwarded to master data
Library 20 or from database 30.
Fig. 1 b is please referred to, specifically, router 10 is used to receive and judge the type of database access request;If the number
It is read request according to the type of library access request, delay threshold and the database access request is encapsulated into database message;
And it is corresponding from database 30 that the database message is sent to primary database 20.That is, in this specification embodiment, router
The routing policy of 10 pairs of database access requests is carried out based on the type of access request, not to master-slave database on router 10
Between principal and subordinate delay judge, but by user require delay threshold be encapsulated into the database message of read request and turn
It is sent to from database 30.
Referring to FIG. 2, the routing procedure of router 10 is such as in a kind of data processing method that this specification embodiment provides
Under:
S21, database access request is received.
S22, packet parsing and SQL (Structured Query are carried out to the database access request received
Language, structured query language) parsing.
The type of database access request that S23, judgement receive, determine the database access request be read request or
Write request.
If the database access request is write request, which is forwarded to primary database.In database
Read and write abruption method in, write request is usually completed by primary database 20, so as to primary database 20 to each from database 30
Synchronize update.
If S24, the database access request are read request, by the database access request and the received delay threshold of user
It is encapsulated into a database message and is forwarded to from database 30.
The feedback message that S25, reception are fed back from database 30 based on database access request.The feedback includes: normal place
The processing result and be unsatisfactory for user demand database access request since principal and subordinate's delay is excessive that reason database access request obtains
Processing failure and the error message fed back.
Whether the feedback message that S26, judgement receive is error message.
If the feedback message is error message, corresponding database access request is sent to primary database 20, so that
Primary database 20 handles the database access request.Conversely, being normal if feedback message is not error message
Processing result then sends it to client.
Fig. 1 b is please referred to, the database message that receiving router 10 is sent is used for from database 30, judges from database 30
Whether the current delay times between primary database 20 are within the scope of the acceptable delay threshold of user;When according to current delay
Between judging result with delay threshold range, respond the database access request.Wherein, judge working as between master-slave database
Whether preceding delay time is within the scope of delay threshold, it can be determined that whether current delay times are less than or equal to delay threshold, if working as
Preceding delay time is less than or equal to delay threshold, then current delay times are within the scope of delay threshold, conversely, then current delay times
Not within the scope of delay threshold.Certainly, judge that current delay times whether within the scope of delay threshold, also may determine that and currently prolong
Whether the slow time is less than delay threshold;If being less than, current delay times are within the scope of delay threshold, conversely, then current delay
Time is not within the scope of delay threshold.It is equal to this point of delay threshold about current delay times, includes or be not included in
Within the scope of delay threshold, the protection scope of the application is belonged to.
Referring to FIG. 3, in a kind of data processing method that this specification embodiment provides, from the treatment process of database 30
It is as follows:
S31, database message is received and parsed through, obtains the delay threshold in database message.
S32, judge current delay times between database 30 and primary database 20 whether within the scope of delay threshold.
Different database access requests has different requirements to principal and subordinate's delay between master-slave database, some access requests are to master
Big from the tolerance of delay, for corresponding delay threshold with regard to big, the tolerance that some access requests are delayed to principal and subordinate is small, corresponding to prolong
When threshold value with regard to small.The setting of delay threshold can be preset by designer according to different access requests, can also by with
Family carries out sets itself and is sent to router 10.Current delay times between database 30 and primary database 20, can be with
By calculating to obtain from database 30 according to the last master-slave database synchronization time and current time.
If S33, the current delay times between database 30 and primary database 20 are within the scope of delay threshold, from data
Library handles the database access request in database message, and returns to processing result.
If S34, the current delay times between database 30 and primary database 20 not within the scope of delay threshold, generate
Error message is simultaneously sent to router 10.Certainly, directly corresponding database access request can be forwarded from database page 30
To primary database 20, primary database 20 is requested to handle the database access request.
In above-described embodiment, the read request in database access request is sent directly to from database by router,
By judge from database the current delay times between database and primary database whether the delay in database message
In threshold range, that is, judge whether principal and subordinate's delay meets user's requirement, no longer principal and subordinate's delay is supervised by intermediate module
It controls and judges, avoid the monitoring delay of middleware, when can obtain the actual delay of master-slave database accurately, in real time
Between, it solves the technical problem of principal and subordinate's delay judgement inaccuracy between master-slave database in the prior art, improves principal and subordinate's delay and sentence
Disconnected accuracy.
Referring to FIG. 4, a kind of data processing method provided based on the above embodiment, this specification embodiment also correspondence is mentioned
For a kind of router, comprising:
Judging unit 41, for judging the type of database access request;
When encapsulation unit 42 for the type in the database access request is read request, by delay threshold and described
Database access request is encapsulated into database message;
Transmission unit 43, it is corresponding from database for the database message to be sent to primary database, so that described
From database based on delay threshold and the current delay times between database and the primary database, the number is responded
According to library access request.
In specific implementation process, the transmission unit 43 is also used to: being to write to ask in the type of the database access request
When asking, the database access request is sent to the primary database.
Further, the router that this specification embodiment provides further include: receiving unit 44, it is described from number for receiving
According to the library feedback message that library access request is fed back based on the data;The judging unit 41 is also used to: judging the feedback report
Whether text is error message;The transmission unit 43 is also used to: when the feedback message is error message, by the database
Access request is forwarded to the primary database, so that the primary database handles the database access request.
Referring to FIG. 5, a kind of data processing method provided based on the above embodiment, this specification embodiment also correspondence is mentioned
For one kind from database, comprising:
Parsing module 51 obtains delay threshold and database access for parsing to the database message received
Request;
Judgment module 52, for judging the current delay times between database and primary database whether described
Within the scope of delay threshold;
Processing module 53, for the judging result according to the current delay times and the delay threshold range, response
The database access request.
It is described from database in specific implementation process further include: the first sending module, in the current delay times
When not within the scope of the delay threshold, generation error message is simultaneously sent to router, so that the router is based on the mistake
The database access request is retransmitted to the primary database by wrong report text.Alternatively, it is described from database can also include: second
Sending module is used for when the current delay times are not within the scope of the delay threshold, by the database access request
It is forwarded to the primary database, the database access request is handled by the primary database.
About in above-described embodiment router, from database, wherein each unit, module execute the concrete mode of operation
It is described in detail in the embodiment of method, no longer elaborates herein.
Referring to FIG. 6, being shown according to an exemplary embodiment a kind of set for realizing the electronics of data processing method
Standby 700 block diagram.For example, electronic equipment 700 can be computer, database console, tablet device, personal digital assistant
Deng.
Referring to Fig. 6, electronic equipment 700 may include following one or more components: processing component 702, memory 704,
Power supply module 706, multimedia component 708, the interface 710 and communication component 712 of input/output (I/O).
The integrated operation of the usual controlling electronic devices 700 of processing component 702 is such as grasped with display, data communication, and record
Make associated operation.Processing element 702 may include one or more processors 720 to execute instruction, above-mentioned to complete
The all or part of the steps of method.In addition, processing component 702 may include one or more modules, it is convenient for 702 He of processing component
Interaction between other assemblies.
Memory 704 is configured as storing various types of data to support the operation in equipment 700.These data are shown
Example includes the instruction of any application or method for operating on electronic equipment 700, contact data, telephone directory number
According to, message, picture, video etc..Memory 704 can by any kind of volatibility or non-volatile memory device or they
Combination realize, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM) is erasable
Programmable read only memory (EPROM), programmable read only memory (PROM), read-only memory (ROM), magnetic memory, quick flashing
Memory, disk or CD.
Power supply module 706 provides electric power for the various assemblies of electronic equipment 700.Power supply module 706 may include power supply pipe
Reason system, one or more power supplys and other with for electronic equipment 700 generate, manage, and distribute the associated component of electric power.
I/O interface 710 provides interface between processing component 702 and peripheral interface module, and above-mentioned peripheral interface module can
To be keyboard, click wheel, button etc..These buttons may include, but are not limited to: home button, volume button, start button and lock
Determine button.
Communication component 712 is configured to facilitate the communication of wired or wireless way between electronic equipment 700 and other equipment.
Electronic equipment 700 can access the wireless network based on communication standard, such as WiFi, 2G or 3G or their combination.Show at one
In example property embodiment, communication component 712 receives broadcast singal or broadcast from external broadcasting management system via broadcast channel
Relevant information.In one exemplary embodiment, the communication component 712 further includes near-field communication (NFC) module, short to promote
Cheng Tongxin.For example, radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra wide band can be based in NFC module
(UWB) technology, bluetooth (BT) technology and other technologies are realized.
In the exemplary embodiment, electronic equipment 700 can be by one or more application specific integrated circuit (ASIC), number
Word signal processor (DSP), digital signal processing appts (DSPD), programmable logic device (PLD), field programmable gate array
(FPGA), controller, microcontroller, microprocessor or other electronic components are realized, for executing the above method.
In the exemplary embodiment, a kind of non-transitorycomputer readable storage medium including instruction, example are additionally provided
It such as include the memory 704 of instruction, above-metioned instruction can be executed by the processor 720 of electronic equipment 700 to complete the above method.Example
Such as, the non-transitorycomputer readable storage medium can be ROM, random access memory (RAM), CD-ROM, tape, soft
Disk and optical data storage devices etc..
A kind of non-transitorycomputer readable storage medium, when the instruction in the storage medium is by the processing of mobile terminal
When device executes, so that electronic equipment is able to carry out a kind of data processing method, which comprises
Judge the type of database access request;If the type of the database access request is read request, by the threshold that is delayed
Value and the database access request are encapsulated into database message;It is corresponding that the database message is sent to primary database
From database so that it is described from database based on delay threshold and currently the prolonging between database and the primary database
The slow time responds the database access request.
Certainly, one of this specification embodiment non-transitorycomputer readable storage medium, when the storage medium
In instruction when being executed by the processor of mobile terminal, it is also possible that electronic equipment is able to carry out a kind of data processing method,
The described method includes:
The database message received from connection is parsed, and delay threshold and database access request are obtained;Sentence
Whether the disconnected current delay times between database and primary database are within the scope of the delay threshold;Worked as according to described
Judging result between preceding delay time and the delay threshold range, responds the database access request.
It should be understood that the present invention is not limited to the precise structure already described above and shown in the accompanying drawings, and
And various modifications and changes may be made without departing from the scope thereof.The scope of the present invention is limited only by the attached claims
The foregoing is merely presently preferred embodiments of the present invention, is not intended to limit the invention, it is all in spirit of the invention and
Within principle, any modification, equivalent replacement, improvement and so on be should all be included in the protection scope of the present invention.