The content of the invention
The embodiments of the invention provide a kind of method and device for realizing read and write abruption, it is possible to increase accesses the effect of databaseRate.
On the one hand, the embodiments of the invention provide a kind of method for realizing read and write abruption, including:
Pre-set primary database and auxiliary database;
Pre-set query interface and write-in interface;
Realize at least one target matrix in the primary database and the auxiliary database in real-time synchronization;
When needing to perform write operation at least one target matrix, using said write interface to the masterAt least one target matrix in database performs write operation;
When needing to perform read operation at least one target matrix, performed using the query interface:
Receive the querying condition of outside input;
At least one target matrix inquired about according to the querying condition in the auxiliary database.
Further,
After at least one target matrix in the auxiliary database according to querying condition inquiry,Further comprise:
When not inquiring the Query Result for meeting the querying condition, the main number is inquired about according to the querying conditionAccording at least one target matrix in storehouse.
Further,
At least one target matrix inquired about according to the querying condition in the primary database, including:
From at least one target matrix in the primary database, inquire about and called before predetermined time periodSaid write interface and write-back are performed in the target record of state with the presence or absence of the record for meeting the querying condition.
Further,
This method further comprises:Pre-set record queue to be checked;
Further comprise:
For the record of at least one target matrix in the primary database, determine to have invoked described write in real timeIncoming interface and write-back perform first record of state;
For each first record, it is performed both by:The predetermined time period is waited from being called said write interfaceAfterwards, using the current first record as the target record, current first record is added to the record queue to be checkedIn;
In at least one target matrix from the primary database, inquire about before predetermined time periodIt has invoked said write interface and write-back and perform in the target record of state and whether there is the record for meeting the querying condition,Including:
Inquire about in the record queue to be checked with the presence or absence of the record for meeting the querying condition.
Further,
It is described to realize that at least one target matrix, with real-time synchronization in the auxiliary database, wraps in the primary databaseInclude:
Realize that the auxiliary database subscribes at least one target in the primary database using transactional replication modeTables of data.
On the other hand, the embodiments of the invention provide a kind of device for realizing read and write abruption, including:
Primary database, auxiliary database, query interface, write-in interface and synchronization module;
The synchronization module, for realizing at least one target matrix in the primary database and the auxiliary databaseMiddle real-time synchronization;
Said write interface, for when needing to perform write operation at least one target matrix, to describedAt least one target matrix in primary database performs write operation;
The query interface, for when needing to perform read operation at least one target matrix, receiving outerThe querying condition of portion's input;At least one target matrix inquired about according to the querying condition in the auxiliary database.
Further,
The query interface, it is further used for described according to being inquired about in the auxiliary database querying conditionAfter at least one target matrix, when not inquiring the Query Result for meeting the querying condition, according to the inquiryAt least one target matrix in primary database described in condition query.
Further,
The query interface, for from least one target matrix in the primary database, inquiring about pre-It whether there is if having invoked said write interface and write-back before time span and perform in the target record of state described in satisfactionThe record of querying condition.
Further,
The device further comprises:Record queue to be checked and add module;
The add module, it is real for the record at least one target matrix in the primary databaseWhen determine have invoked said write interface and write-back perform state first record, for it is each it is described first record, holdOK:After waiting the predetermined time period from being called said write interface, current first is recorded as the target record,Current first record is added in the record queue to be checked;
The query interface, for inquiring about in the record queue to be checked with the presence or absence of the note for meeting the querying conditionRecord.
Further,
The synchronization module, for realizing that the auxiliary database is subscribed in the primary database using transactional replication modeAt least one target matrix.
In embodiments of the present invention, there is provided primary database and auxiliary database, there is provided query interface and interface is write, extremelyFew target matrix real-time synchronization in primary database and in auxiliary database, when needing to perform write operation, pass through write-inInterface performs write operation to primary database, and when needing read operation, auxiliary database is inquired about using query interface, realShow read and write abruption, reduced the situation of wait, shortened the time of wait, improve the efficiency for accessing database.
Embodiment
To make the purpose, technical scheme and advantage of the embodiment of the present invention clearer, below in conjunction with the embodiment of the present inventionIn accompanying drawing, the technical scheme in the embodiment of the present invention is clearly and completely described, it is clear that described embodiment isPart of the embodiment of the present invention, rather than whole embodiments, based on the embodiment in the present invention, those of ordinary skill in the artThe every other embodiment obtained on the premise of creative work is not made, belongs to the scope of protection of the invention.
As shown in figure 1, the embodiments of the invention provide a kind of method for realizing read and write abruption, this method can include followingStep:
Step 101:Pre-set primary database and auxiliary database;
Step 102:Pre-set query interface and write-in interface;
Step 103:Realize that at least one target matrix is same in real time in the primary database and in the auxiliary databaseStep;
Step 104:When needing to perform write operation at least one target matrix, said write interface is utilizedWrite operation is performed at least one target matrix in the primary database;
Step 105:When needing to perform read operation at least one target matrix, the query interface is utilizedPerform:
Receive the querying condition of outside input;
At least one target matrix inquired about according to the querying condition in the auxiliary database.
In embodiments of the present invention, there is provided primary database and auxiliary database, there is provided query interface and interface is write, extremelyFew target matrix real-time synchronization in primary database and in auxiliary database, when needing to perform write operation, pass through write-inInterface performs write operation to primary database, and when needing read operation, auxiliary database is inquired about using query interface, realShow read and write abruption, reduced the situation of wait, shortened the time of wait, improve the efficiency for accessing database.
In order to ensure the accuracy of Query Result, in an embodiment of the present invention, looked into described according to the querying conditionAfter asking at least one target matrix in the auxiliary database, further comprise:
When not inquiring the Query Result for meeting the querying condition, the main number is inquired about according to the querying conditionAccording at least one target matrix in storehouse.
When realizing at least one target matrix in primary database with real-time synchronization in auxiliary database, it is understood that there may beDelay so that at least one target matrix in auxiliary database is not newest, and causes not find satisfaction inquiry barThe Query Result of part, for such case, in embodiments of the present invention, meet inquiry bar when not inquired in auxiliary databaseDuring the Query Result of part, secondary-confirmation is carried out into primary database, the Query Result caused by synchronization delay is avoided and is forbiddenThe problem of true so that Query Result is more accurate.
In embodiments of the present invention, if inquire the Query Result for meeting querying condition in auxiliary database, returnQuery Result;If not inquiring the Query Result for meeting querying condition in auxiliary database, inquired in primary databaseMeet the Query Result of querying condition, then return to the Query Result, if also not inquiring satisfaction inquiry in primary databaseThe Query Result of condition, then return without this record.
In addition, when returning to Query Result, the Query Result can be encapsulated according to the return form made an appointment, returns to envelopeQuery Result after dress.
In an embodiment of the present invention, it is described at least one according to being inquired about in the primary database querying conditionIndividual target matrix, including:
From at least one target matrix in the primary database, inquire about and called before predetermined time periodSaid write interface and write-back are performed in the target record of state with the presence or absence of the record for meeting the querying condition.
In embodiments of the present invention, when inquiring about primary database, simply inquiry meets the record of following two conditions:DefaultWrite-in interface, write-back execution state are called before time span.For not calling also the record of write-in interface not allowInquiry, these records are to be not present, and exclude this part record, reduce the workload of inquiry.In addition, write-back execution state is saidWarp-wise primary database is transmitted across the bright record, if performing state without write-back, the record is not passed into primary databaseDefeated mistake, the record is to be not present, it is therefore not necessary to be inquired about, excludes this part record, reduces the workload of inquiry.At thisIn inventive embodiments, when inquiring about primary database, simply inquire about and said write interface and write-back are called before predetermined time periodThe target record of the state of execution, greatly reduces the workload of inquiry, improves search efficiency.
In embodiments of the present invention, predetermined time period can be 10s, 20s, 30s etc..It is before predetermined time periodRefer to before the predetermined time period at current time, such as:Refer to before 30s before the 30s at current time, if currentlyMoment is 1:00:30, then, refer to before 30s 1:00:Before 00.
In an embodiment of the present invention, this method further comprises:Pre-set record queue to be checked;
Further comprise:
For the record of at least one target matrix in the primary database, determine to have invoked described write in real timeIncoming interface and write-back perform first record of state;
For each first record, it is performed both by:The predetermined time period is waited from being called said write interfaceAfterwards, using the current first record as the target record, current first record is added to the record queue to be checkedIn;
In at least one target matrix from the primary database, inquire about before predetermined time periodIt has invoked said write interface and write-back and perform in the target record of state and whether there is the record for meeting the querying condition,Including:
Inquire about in the record queue to be checked with the presence or absence of the record for meeting the querying condition.
In embodiments of the present invention, target record is added in record queue to be checked in real time, when query interface needsWhen inquiring about target record, inquired about directly into record queue to be checked, without being inquired about from whole primary database, greatlyThe big time saved required for inquiry, improve search efficiency.
In an embodiment of the present invention, it is described to realize that at least one target matrix is in the primary database and described auxiliaryReal-time synchronization in database, including:
Realize that the auxiliary database subscribes at least one target in the primary database using transactional replication modeTables of data.
The delay that transactional replication mode synchronizes is smaller, and synchronous effect is more preferable, is more suitable in the embodiment of the present inventionRead and write abruption scene.In embodiments of the present invention, the synchronization of target matrix is realized by transactional replication mode, synchronous prolongsSmaller late, synchronous effect is more preferable so that Query Result is more accurate.
In embodiments of the present invention, auxiliary database have subscribed at least one target matrix in primary database, when main numberWhen being updated according at least one target matrix in storehouse, corresponding at least one target matrix also can in auxiliary databaseSynchronized update.
Furthermore it is also possible to by snapshot mode or merge copy mode to realize the same of auxiliary database and primary databaseStep.
As shown in Fig. 2 the embodiments of the invention provide a kind of method for realizing read and write abruption, this method can include followingStep:
Step 201:Pre-set primary database, auxiliary database, query interface, write-in interface and record queue to be checked.
Specifically, primary database and auxiliary database are used at least one target matrix being present.Record queue to be checked is usedIn storage target record.
Step 202:Realize that auxiliary database subscribes at least one target data in primary database using transactional replication modeTable.
For example, Table A is a target matrix, then realizes that auxiliary database subscribes to master data using transactional replication modeAfter Table A in storehouse, when the Table A in primary database updates, the Table A in auxiliary database also can synchronized update.
Step 203:When needing to perform write operation at least one target matrix, using writing interface to main numberWrite operation is performed according at least one target matrix in storehouse.
Specifically, write operation simply primary database is handled, write operation include increase operation, deletion action,Modification operation.
Step 204:For the record of at least one target matrix in primary database, determine to have invoked write-in in real timeInterface and write-back perform first record of state;For each first record, it is performed both by:Waited from calling and writing interface pre-If after time span, using the current first record as target record, the current first record is added in record queue to be checked.
For example, predetermined time period 30s.Write-in interface is called to be written with record A in primary database, also,For recording A write-backs execution state, for recording A, since being called the operation of write-in interface corresponding to record A, wait 30sAfterwards, using record A as target record, record A is added in record queue to be checked.
Step 205:When needing to perform read operation at least one target matrix, received using query interface outerThe querying condition of portion's input.
For example, the querying condition can be unique code of a record.Wherein, each record in target matrixAll correspond to a unique code., can be according to the corresponding note of this unique yard inquiry when one unique code to be checked of outside inputRecord.
Step 206:Judged using query interface at least one target matrix in auxiliary database with the presence or absence of fullThe Query Result of sufficient querying condition, if it is, performing step 207, otherwise, perform step 208.
Step 207:Query Result is returned using query interface.
Specifically, Query Result can be packaged according to the encapsulation format of agreement, returns to the Query Result after encapsulation.
Step 208:Inquired about using query interface and whether there is the record for meeting querying condition in record queue to be checked, such asFruit is then to perform step 209, otherwise, performs step 210.
Specifically, when inquiring about primary database, simply the target record in record queue to be checked is inquired about.
Step 209:Return to the record for meeting querying condition.
Step 210:Return to the response message that the record for meeting querying condition is not present.
In embodiments of the present invention, the read and write abruption of database is realized, the data source that interface will be write with read interfaceSeparation, write-in interface are based on primary database, read interface and are based on auxiliary database, solve systematicness caused by read-write crossing instancesCan problem.
In embodiments of the present invention, following agreement is pre-set:Once at most inquiry n bars record.So, one query connectsMouth can only at most inquire about n bars record.
As shown in Figure 3, Figure 4, the embodiments of the invention provide a kind of device for realizing read and write abruption.Device embodiment can be withRealized, can also be realized by way of hardware or software and hardware combining by software.For hardware view, as shown in figure 3,For it is provided in an embodiment of the present invention it is a kind of realize read and write abruption device where equipment a kind of hardware structure diagram, except Fig. 3 institutesOutside the processor, internal memory, network interface and the nonvolatile memory that show, the equipment in embodiment where device is generally alsoOther hardware can be included, be such as responsible for the forwarding chip of processing message.Exemplified by implemented in software, as shown in figure 4, as oneDevice on individual logical meaning, it is to be referred to corresponding computer program in nonvolatile memory by the CPU of equipment where itOrder reads what operation in internal memory was formed.A kind of device for realizing read and write abruption that the present embodiment provides, including:
Primary database 401, auxiliary database 402, query interface 403, write-in interface 404 and synchronization module 405;
The synchronization module 405, for realizing that at least one target matrix is in the primary database 401 and described auxiliaryReal-time synchronization in database 402;
Said write interface 404, for when needing to perform write operation at least one target matrix, to instituteAt least one target matrix stated in primary database 401 performs write operation;
The query interface 403, for when needing to perform read operation at least one target matrix, receivingThe querying condition of outside input;At least one number of targets inquired about according to the querying condition in the auxiliary database 402According to table.
In an embodiment of the present invention, the query interface, it is further used for being inquired about according to the querying condition describedAfter at least one target matrix in the auxiliary database, when not inquiring the inquiry that meets the querying conditionWhen as a result, according at least one target matrix in the querying condition inquiry primary database.
In an embodiment of the present invention, the query interface, for from least one mesh in the primary databaseMark in tables of data, inquire about before predetermined time period and have invoked the target record that said write interface and write-back perform stateIn with the presence or absence of meeting the record of the querying condition.
In an embodiment of the present invention, the device further comprises:Record queue to be checked and add module;
The add module, it is real for the record at least one target matrix in the primary databaseWhen determine have invoked said write interface and write-back perform state first record, for it is each it is described first record, holdOK:After waiting the predetermined time period from being called said write interface, current first is recorded as the target record,Current first record is added in the record queue to be checked;
The query interface, for inquiring about in the record queue to be checked with the presence or absence of the note for meeting the querying conditionRecord.
In an embodiment of the present invention, the synchronization module, for realizing the auxiliary database using transactional replication modeSubscribe at least one target matrix in the primary database.
In an embodiment of the present invention, the device further comprises:First configuration module, outside input is received for working asUnlatching read and write abruption pattern order when, configuration querying interface so that query interface can be to the inquiry of auxiliary database, when connecingWhen receiving the order of closing read and write abruption pattern of outside input, configuration querying interface so that query interface is not to auxiliary databaseInquired about, directly primary database is inquired about.
In an embodiment of the present invention, the device further comprises:Second configuration module, outside input is received for working asUnlatching secondary-confirmation pattern order when, configuration querying interface so that query interface can be inquired about in auxiliary database less thanDuring Query Result, primary database is inquired about, when receiving the order of closing secondary-confirmation pattern of outside input, configurationQuery interface so that when query interface is inquired about less than Query Result in auxiliary database, it is impossible to inquire about primary database.
The contents such as the information exchange between each unit, implementation procedure in said apparatus, due to implementing with the inventive methodExample is based on same design, and particular content can be found in the narration in the inventive method embodiment, and here is omitted.
The embodiments of the invention provide a kind of computer-readable recording medium, including execute instruction, when the computing device of storage controlDuring the execute instruction, the storage control perform it is provided in an embodiment of the present invention any one realize the side of read and write abruptionMethod.
The embodiments of the invention provide a kind of storage control, including:Processor, memory and bus;
The memory is used to store execute instruction, and the processor is connected with the memory by the bus, whenDuring the storage control operation, the execute instruction of memory storage described in the computing device, so that the storage controlDevice performs any one method for realizing read and write abruption provided in an embodiment of the present invention.
The each embodiment of the present invention at least has the advantages that:
1st, in embodiments of the present invention, there is provided primary database and auxiliary database, there is provided query interface and interface is write,At least one target matrix real-time synchronization in primary database and in auxiliary database, when needing to perform write operation, by writingIncoming interface performs write operation to primary database, and when needing read operation, auxiliary database is inquired about using query interface,Read and write abruption is realized, reduces the situation of wait, shortens the time of wait, improves the efficiency for accessing database.
2nd, in embodiments of the present invention, when not inquiring the Query Result for meeting querying condition in auxiliary database,Secondary-confirmation is carried out into primary database, is avoided because of the Query Result inaccuracy caused by synchronization delay the problem of so that look intoIt is more accurate to ask result.
3rd, in embodiments of the present invention, when inquiring about primary database, simply inquire about before predetermined time period described in callingThe target record that interface and write-back perform state is write, the workload of inquiry is greatly reduced, improves search efficiency.
4th, in embodiments of the present invention, target record is added in record queue to be checked in real time, when query interface needsWhen inquiring about target record, inquired about directly into record queue to be checked, without being inquired about from whole primary database,The time required for inquiry is greatlyd save, improves search efficiency.
It should be noted that herein, such as first and second etc relational terms are used merely to an entityOr operation makes a distinction with another entity or operation, and not necessarily require or imply and exist between these entities or operationAny this actual relation or order.Moreover, term " comprising ", "comprising" or its any other variant be intended to it is non-It is exclusive to include, so that process, method, article or equipment including a series of elements not only include those key elements,But also the other element including being not expressly set out, or also include solid by this process, method, article or equipmentSome key elements.In the absence of more restrictions, by sentence " including the key element that a 〃 〃 " is limited, it is not excluded thatOther identical factor in the process including the key element, method, article or equipment also be present.
One of ordinary skill in the art will appreciate that:Realizing all or part of step of above method embodiment can pass throughProgrammed instruction related hardware is completed, and foregoing program can be stored in computer-readable storage medium, the programUpon execution, the step of execution includes above method embodiment;And foregoing storage medium includes:ROM, RAM, magnetic disc or lightDisk etc. is various can be with the medium of store program codes.
It is last it should be noted that:Presently preferred embodiments of the present invention is the foregoing is only, is merely to illustrate the skill of the present inventionArt scheme, is not intended to limit the scope of the present invention.Any modification for being made within the spirit and principles of the invention,Equivalent substitution, improvement etc., are all contained in protection scope of the present invention.