A kind of apparatus and method realizing business bank switching fast
Technical field
The present invention relates to technical field of memory, particularly relate to a kind of apparatus and method realizing business bank switching fast.
Background technology
As shown in Figure 1, with a kind of watch-dog, web camera IPC is that example illustrates.This IPC carries storage resources function, namely requires IPC to be provided with can to carry out the resource stored, such as CF card.Usual IPC monitor data first writes buffer memory, then by IP network, the monitor data in buffer memory is stored into the rear end memory device IPSAN of monitor network by iSCSI or other agreements.But store in rear end and break down, and when certain time-out time internal fault also exists, the data in IPC buffer memory will be stored in its storage resources carried, and realize buffer memory amended record function.For convenience of description, by buffer memory called after A, B, C tri-data fields.Suppose that monitor data writes ABC data field successively, then when rear end storage resources can normally write, in ABC tri-data fields data will write successively on the memory device of rear end, and the new monitor data of IPC also can the ABC region of recurrent wrIting buffer memory, namely C data field write full after again write from A data field.But, when rear end storage is broken down, when comprising network failure and rear end storage device failure, after IPC detects this fault, if in time-out time, such as in 15 seconds, when the data in IPC buffer memory still cannot write rear end memory device, the data not being written to rear end memory device are all written on storage resources that IPC carries in buffer memory.These data do not write comprise: start stored in rear end memory device but the data of unsuccessful data and new write buffer memory.First data all in buffer memory are all read, with the data of up-to-date write, on the storage resources that all write IPC carries, so realize buffer memory amended record function.What time-out time here relied on is write order time-out.
Under the prerequisite that IPC cache size is fixing, if by write order time-out time detection mode triggering local cache amended record function, just may appear at write order time-out time also not then, buffer memory is capped write just, causes the capped loss of partial buffering data.In this case, enable buffer memory amended record function even if follow-up, still will cause the imperfect of data.In particular, when IPC code check is larger, the buffer memory amended record started in this way all can cause loss of data usually.
Usually, can consider to shorten time-out time to solve the problem that buffer memory is coated to overwrite.But, due to time-out time once setting is exactly a regular time, so itself can not adapt to the different situation of the code stream of different business.Such as time-out time is set as 8 seconds, and when the code check of IPC is 4M, buffer memory can not be coated to overwrite, and data can not be lost, but data may will be lost when 8M.And if according to the code check of 8M, time-out time is set, be such as set to 4 seconds, that is for 1M, 2M, 4M code check, and this time-out time is too short again, can remain more buffer memory.Because the performance of buffer memory is always higher than storage resources such as CF cards, so it is necessary for preferentially carrying out buffer memory.
Summary of the invention
In view of this, the invention provides a kind of apparatus and method realizing business bank switching fast.
This application of installation realizing business bank switching is fast in the equipment with buffer memory amended record function, this device opens use when rear end storage failure, this equipment comprises local storage resources, and this device comprises: remaining cache computing module, for calculating the length of current residual spatial cache; Described current residual spatial cache for complete rear end store business datum shared by space or without business datum write space; Buffer memory amended record judge module, for judging whether to carry out buffer memory amended record according to the current residual spatial cache length calculated and current business datum length to be written, if current residual spatial cache is less than current business datum length to be written, informing business Data write. module performs buffer memory amended record; If current residual spatial cache is greater than current business datum to be written, informing business writing module performs buffer memory write; Business datum writing module, for when performing buffer memory amended record, writes local storage resources by the business datum not completing rear end storage in buffer memory and current business datum to be written; When performing buffer memory write, by current business datum to be written write buffer memory.
Preferably, remaining cache computing module utilizes following formula to carry out remaining cache calculating: FreeLen=CacheLen-((WritePos+ (CacheLen+1)-ReadPos) % (CacheLen+1)); FreeLen is remaining cache space length; CacheLen is the total length of buffer memory; WritePos is the address of current service data write buffer memory; Address is read in the buffer memory that ReadPos is corresponding when being rear end storage failure.
Preferably, device also comprises: buffer memory amended record is opened and confirmed module, and for confirming whether buffer memory amended record opens, if buffer memory amended record is opened, informing business Data write. module performs buffer memory amended record; If buffer memory amended record is not opened, then performed the judgement of buffer memory amended record by buffer memory amended record judge module; Buffer memory amended record is initially set to closedown; Fault recovery judge module, for executing after business datum writes the operation of local storage resources at business datum writing module, judge whether rear end storage failure recovers, if recovered, the amended record of notice buffer memory arranges module and closes buffer memory amended record; Buffer memory amended record arranges module, during for judging to perform buffer memory amended record at buffer memory amended record judge module, opens buffer memory amended record.
The present invention also provides a kind of method realizing business bank switching fast, the method is applied to the equipment with buffer memory amended record function, the method opens use when rear end storage failure, and this equipment comprises local storage resources, and the method comprises: the length calculating current residual spatial cache; Judge whether to carry out buffer memory amended record according to the current residual spatial cache length calculated and current business datum length to be written, if current residual spatial cache is less than current business datum length to be written, perform buffer memory amended record: the business datum not completing rear end storage in buffer memory and current business datum to be written are write local storage resources; If current residual spatial cache is greater than current business datum to be written, then do not perform buffer memory amended record: by current business datum to be written write buffer memory.
Preferably, the calculating of this remaining cache space length is specially: FreeLen=CacheLen-((WritePos+ (CacheLen+1)-ReadPos) % (CacheLen+1)); FreeLen is remaining cache space length; CacheLen is the total length of buffer memory; WritePos is the address of current service data write buffer memory; Address is read in the buffer memory that ReadPos is corresponding when being rear end storage failure.
The present invention also provides a kind of method realizing business bank switching fast, the method is applied to the equipment with buffer memory amended record function, and the method opens use when rear end storage failure, and this equipment comprises local storage resources, it is characterized in that, the method comprises the steps:
A, when business datum write operation will be performed, judge whether buffer memory amended record opens, if so, perform step B; If not, step C is performed;
B, by buffer memory do not complete rear end store business datum and current business datum to be written write local storage resources; Go to step F;
C, judge whether cache residual space length is greater than data length to be written, if so, perform step D; If not, step e is performed;
D, by current business datum to be written write buffer memory, go to step A;
E, by buffer memory do not complete business datum that rear end stores and current business datum to be written writes local storage resources, and open buffer memory amended record; Go to step F;
F, judge whether rear end storage failure recovers; If so, step G is performed; If not, steps A is returned;
G, the amended record of closedown buffer memory.
Preferably, the calculating of remaining cache space length is specially: FreeLen=CacheLen-((WritePos+ (CacheLen+1)-ReadPos) % (CacheLen+1)); FreeLen is remaining cache space length; CacheLen is the total length of buffer memory; WritePos is the address of current service data write buffer memory; Address is read in the buffer memory that ReadPos is corresponding when being rear end storage failure.
Compared to prior art, the technology of the present invention, when rear end storage failure, starts the function of local cache amended record timely, ensures to switch in time to prevent loss of data.
Accompanying drawing explanation
Fig. 1 is that existing IPC stores exemplary plot.
Fig. 2 is the logical diagram of one embodiment of the present invention device.
Fig. 3 is the example key diagram of one embodiment of the present invention.
Fig. 4 is the process flow diagram of one embodiment of the present invention.
Fig. 5 is further embodiment of this invention process flow diagram.
Fig. 6 is the present invention's another embodiment device logical diagram.
Embodiment
For solving the problem of prior art, the present invention proposes a kind of device realizing business bank switching fast, and this application of installation is in the equipment with local storage resources.This has the equipment of local storage resources and communicates with the memory device in network, business datum is stored on this memory device in a network.Memory device in this network exists as a kind of rear end storage resources, receives business datum to be stored and stores.Ginseng Fig. 2, this device realizing business bank switching fast logically can be divided into: remaining cache computing module, buffer memory amended record judge module and business datum writing module.These modules perform following function on equipment:
Remaining cache computing module, for calculating the length of current residual spatial cache; Described current residual spatial cache for complete rear end store business datum shared by space or without business datum write space;
Buffer memory amended record judge module, for judging whether to carry out buffer memory amended record according to the current residual spatial cache length calculated and current business datum length to be written, if current residual spatial cache is less than current business datum length to be written, perform buffer memory amended record; If current residual spatial cache is greater than current business datum to be written, then do not perform buffer memory amended record;
Business datum writing module, for when performing buffer memory amended record, writes local storage resources by the business datum not completing rear end storage in buffer memory and current business datum to be written; When not performing buffer memory amended record, by current business datum to be written write buffer memory.
Be described below in conjunction with a concrete example.Please refer to the drawing 3, the video data after web camera IPC encodes first stored in local cache, then from buffer memory sense data again by monitor network stored in rear end storage resources.When the one piece of data started by cache location r reads write rear end storage resources, occurred fault, current business datum writing position is w.Remaining cache computing module calculates current residual spatial cache length.Remaining cache computing module can use following formula to carry out the calculating of remaining cache: FreeLen=CacheLen-((WritePos+ (CacheLen+1)-ReadPos) % (CacheLen+1)); FreeLen is remaining cache space length; CacheLen is the total length of buffer memory; WritePos is the address of current service data write buffer memory; Address is read in the buffer memory that ReadPos is corresponding when being rear end storage failure.Certainly, except this formula, do not get rid of the formula that other can realize remaining cache calculating.The corresponding ReadPos of position w corresponding WritePos, position r in Fig. 3.Remaining cache space is the region of drawing slash in Fig. 3.Data in this slash region are the business datum having completed rear end storage.Certainly, do not carry out just breaking down when covering is write if rear end is stored in buffer memory, the subregion (to buffer memory end from w position) in this slash region just exists without business datum.The data of not drawing in the buffer zone of slash are the business datum not writing rear end storage resources.
Buffer memory amended record judge module judges the size of new video data length IPCLen in current buffer memory to be written and remaining cache space length FreeLen, if FreeLen>IPCLen, then informing business Data write. module is by the new video data write buffer memory in current buffer memory to be written; If FreeLen<IPCLen, then informing business Data write. module is by the local storage resources of the new video data write IPC in current buffer memory to be written, namely carries out buffer memory amended record function.If FreeLen=IPCLen, then the new video data in buffer memory to be written can write in buffer memory, also can write local storage resources.For Fig. 3, namely compare slash region and new video data length to be written, and whether perform buffer memory amended record function according to above-mentioned rule judgment.
When rear end storage failure, before new video data performs buffer memory write, perform above-mentioned calculating and judgement by remaining cache computing module and buffer memory amended record judge module, to determine whether new video data will perform buffer memory amended record operation at every turn.
Remaining cache computing module and the calculating performed by buffer memory amended record judge module and judgement action might not perform when rear end storage failure.When rear end storage is not broken down, these two functional modules also can perform corresponding operation.
Below in conjunction with Fig. 4, a kind of embodiment of the method process flow diagram realizing business bank switching fast of the present invention is described.When rear end storage failure, the method performs following steps:
When S41, business datum write operation, calculate the length of current residual spatial cache;
Front end surveillance device collects video traffic data and encodes, and performs write operation to this business datum after coding.
S42, according to calculate current residual spatial cache length and current business datum length to be written judge whether to carry out buffer memory amended record, if current residual spatial cache is less than current business datum length to be written, perform buffer memory amended record: the business datum not completing rear end storage in buffer memory and current business datum to be written are write local storage resources; If current residual spatial cache is greater than current business datum to be written, then do not perform buffer memory amended record: by current business datum to be written write buffer memory.
Said method, when rear end storage is broken down, needs for each follow-up business datum write operation the flow process performing Fig. 4, when namely carrying out business datum write operation, all will perform the judgement of step S42 at every turn.Fig. 5 gives another embodiment optimized.In this embodiment, once perform buffer memory amended record, if the unrecovered words of non-rear end storage failure, follow-up data writing operation each time will all perform buffer memory amended record.Be described in detail below in conjunction with Fig. 5.
When rear end storage failure, the present embodiment method performs the step as Fig. 5:
Step 51, when business datum write operation will be performed, judge whether buffer memory amended record opens.If so, step 52 is performed; If not, step 53 is performed.
Whether buffer memory amended record is opened and can be represented by a zone bit, and such as, this is masked as is 1, represents that buffer memory amended record is opened; This zone bit is that 0 expression buffer memory amended record is not opened.Buffer memory amended record is opened and is referred to: previous business datum write operation performs buffer memory amended record function.Time initial, this mark position 0.
Step 52, by buffer memory do not complete rear end store business datum and current business datum to be written write local storage resources.Go to step 56.
Step 53, judge whether cache residual space is greater than data length to be written.If so, step 54 is performed.If not, step 55 is performed.
Step 54, by current business datum to be written write buffer memory.Return step 51.
Step 55, by buffer memory do not complete business datum that rear end stores and current business datum to be written writes local storage resources, and open buffer memory amended record.Go to step 56.
Step 56, judge whether rear end storage failure recovers.If so, step 57 is performed; If not, step 51 is returned.
Step 57, the amended record of closedown buffer memory.
Close buffer memory amended record, will the mark position 0 of buffer memory amended record be represented.
Based on the design of Fig. 5, the another device realizing business bank switching fast of the present invention, on the basis of the device described by Fig. 2, also comprises: buffer memory amended record is opened and confirmed that module, fault recovery judge module and buffer memory amended record arrange module, please refer to the drawing 6.Buffer memory amended record is opened and is confirmed module, and for confirming whether buffer memory amended record opens, if buffer memory amended record is opened, informing business Data write. module performs buffer memory amended record; If buffer memory amended record is not opened, then performed the judgement of buffer memory amended record by buffer memory amended record judge module; Buffer memory amended record is initially set to closedown; Fault recovery judge module, for executing after business datum writes the operation of local storage resources at business datum writing module, judge whether rear end storage failure recovers, if recovered, the amended record of notice buffer memory arranges module and closes buffer memory amended record; Buffer memory amended record arranges module, during for judging to perform buffer memory amended record at buffer memory amended record judge module, opens buffer memory amended record.
By the technology of the present invention, when rear end storage failure, start the function of local cache amended record timely, ensure to switch in time to prevent loss of data.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, within the spirit and principles in the present invention all, any amendment made, equivalent replacement, improvement etc., all should be included within the scope of protection of the invention.