Summary of the invention
Be to solve the technical matters that exists in the prior art, the invention provides and a kind ofly have no progeny in the Data Update under fortuitous event occurring, re-powering can be fast and the storage and update method and the device that reliably data are upgraded.
The present invention solves the problems of the technologies described above, the technical scheme that adopts is: a kind of data storage and update method are provided, may further comprise the steps, step 10, identical data before the memory block of three formed objects of planning and the difference storage update, three memory blocks are memory block S1, memory block S2 and memory block S3 successively; Step 20 is carried out the event that meets accident in the process of Data Update to three memory blocks successively, causes Data Update to be interrupted; Step 30, again three memory blocks are powered on, read successively the data of storage in memory block S1 and the memory block S2, if the data of memory block S1 are identical with the data of memory block S2, then take the data of memory block S1 as valid data VD, and the data in the S3 of memory block are carried out consistent update, otherwise take the data of memory block S3 as valid data VD, and the data in memory block S1, the memory block S2 are carried out consistent update.
As preferred version of the present invention, described step 30 is further comprising the steps, and step 31 powers on to three memory blocks, and reads respectively the interior data D1 of memory block S1 and the data D2 in the S2 of memory block; Step 32 is carried out relatively data D1 and data D2, if data D1 is identical with data D2, then enters step 33, otherwise skips to step 36; Step 33 reads the data D3 in the S3 of memory block, and judges that whether data D3 is identical with data D2, if identical, then skips to step 35; If different, then enter step 34; Step 34 is updated to memory block S3 with data D1; Step 35, return data D1 finishes as valid data VD; Step 36 reads the data D3 in the S3 of memory block, and judges that whether data D3 is identical with data D2, if identical, then skips to step 38, otherwise enters step 37; Step 37 is updated to memory block S2 with data D3; Step 38 is updated to memory block S1 with data D3; Step 39, return data D3 finishes as valid data VD.
The present invention solves the problems of the technologies described above, and the technical scheme that adopts is: a kind of data storage and updating device are provided, comprise memory block S1, memory block S2, the memory block S3 of three formed objects, and the data that store these three memory blocks are identical; Because having to upgrade, unscheduled event do not finish above-mentioned three memory blocks being carried out in the data updating process; Again after three memory blocks being powered on, read successively the data of storage in memory block S1 and the memory block S2, if the data of memory block S1 are identical with the data of memory block S2, then take the data of memory block S1 as valid data VD, and the data in the S3 of memory block are carried out consistent update, otherwise take the data of memory block S3 as valid data VD, and the data in memory block S1, the memory block S2 are carried out consistent update.
Technical scheme of the present invention is with respect to prior art, the beneficial effect of obtaining; Data storage of the present invention and update method and device, utilize the redundant copies of data of three memory blocks, by the validity of simple judgement recognition data, even the phenomenon of obliterated data also can not appear in the event that meets accident in operating process (such as power down or reset).Adopt such scheme, not only guaranteed the safety of data, and its computing is also very simple, does not need to take a large amount of CPU (controller) resource.
Embodiment
In order to make technical matters to be solved by this invention, technical scheme and beneficial effect clearer, clear, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein only in order to explain the present invention, is not intended to limit the present invention.
Such as Fig. 1, shown in Figure 3, data storage of the present invention and update method is characterized in that, may further comprise the steps 10 to step 30.Wherein,
Step 10, the identical data before the memory block of three formed objects of planning and the difference storage update, three memory blocks are memory block S1, memory block S2 and memory block S3 successively.The memory block can as required, be opened up at primary memory, supplementary storage, cache memory.Data can be system core data, also can be other data higher to security level required.
Step 20 is carried out the event that meets accident in the process of Data Update to three memory blocks successively, causes Data Update to be interrupted.Unscheduled event can be such as power down or the reason such as reset, and can occur by any time point in data updating process.
Step 30, again three memory blocks are powered on, read successively the data of storage in memory block S1 and the memory block S2, if the data of memory block S1 are identical with the data of memory block S2, then take the data of memory block S1 as valid data VD, and the data in the S3 of memory block are carried out consistent update, otherwise take the data of memory block S3 as valid data VD, and the data in memory block S1, the memory block S2 are carried out consistent update.
For step 30, may further include following steps, as shown in Figure 2,
Step 31 powers on to three memory blocks, and reads respectively the interior data D1 of memory block S1 and the data D2 in the S2 of memory block;
Step 32 is carried out relatively data D1 and data D2, if data D1 is identical with data D2, then enters step 33, otherwise skips to step 36;
Step 33 reads the data D3 in the S3 of memory block, and judges that whether data D3 is identical with data D2, if identical, then skips to step 35; If different, then enter step 34;
Step 34 is updated to memory block S3 with data D1;
Step 35, return data D1 finishes as valid data VD;
Step 36 reads the data D3 in the S3 of memory block, and judges that whether data D3 is identical with data D2, if identical, then skips to step 38, otherwise enters step 37;
Step 37 is updated to memory block S2 with data D3;
Step 38 is updated to memory block S1 with data D3;
Step 39, return data D3 finishes as valid data VD.
As shown in Figure 3, specifically, namely be,
The data that X-store the memory block before writing;
The data that store the memory block in Y-ablation process;
Z-the write data that store the memory block when finishing.
Sequence number 1: event meets accident before renewal.Data D3 in the data D2 in the data D1 in the S1 of memory block, memory block S2, memory block S3 is all raw data X, since D1=D2=D3=X, therefore, after re-powering, data in memory block S2, the memory block S3 still are X, return as valid data VD with the data X in the S1 of memory block.
Sequence number 2, event meets accident when writing memory block S1.This moment is because the data D1 in the S1 of memory block changes D1=Y, and D2=D3=X.Do not finish because the data D1 in the S1 of memory block upgrades, data have lost integrality.Therefore, after re-powering, with the data D3 in the S3 of memory block the data Y in the S1 of memory block is updated to X, returns as valid data VD with the data X in the S3 of memory block.
Sequence number 3, event meets accident when just in time writing memory block S1.The interior data D1 of memory block S1 this moment changes D1=Z.Although the data D1 in the memory block upgrades and finishes at this moment, data have integrality, and the difficult judgement of computing machine or judgement need to the more hardware costs of cost.At this moment, processing mode such as sequence number 2, namely be, with the data D3 in the S3 of memory block the data Y in the S1 of memory block is updated to X, return as valid data VD with the data X in the S3 of memory block.
Sequence number 4, event meets accident when writing memory block S2.At this moment, the data D1 in the S1 of memory block upgrades and finishes D1=Z; And the data D2 in the S2 of memory block does not have renewal to finish, and loses the integrality of data, D2=Y; Data D3 in the S3 of memory block still is raw data X.At this moment, the data with in the data X in the S3 of memory block successively updated stored district S2 and the memory block S1 make D3=D2=D1=X, and return as valid data VD with the data X in the S3 of memory block.
Sequence number 5, event meets accident when just in time writing memory block S2.The relation of data D2 in data D1, the memory block S2 in the S1 of memory block is at this moment: D1=D2=Z.At this moment, the data with in the data Z updated stored district S3 in the S1 of memory block make D1=D2=D3=Z, and return as valid data VD with the data Z in the S1 of memory block.
Sequence number 6, event meets accident when writing memory block S3.At this moment, the data relationship in memory block S1, memory block S2, the memory block S3 is: D1=D2=Z, D3=Y.At this moment, the data with in the data Z updated stored district S3 in the S1 of memory block make D1=D2=D3=Z, and return as valid data VD with the data Z in the S1 of memory block.
Sequence number 7, event meets accident when just in time writing memory block S3.At this moment, the data relationship in memory block S1, memory block S2, the memory block S3 is: D1=D2=D3=Z.At this moment, return as valid data VD with the data Z in the S1 of memory block.
As shown in Figure 4, the present invention also provides a kind of data storage and updating device for solving the technical matters that exists in the prior art, comprise memory block S1, memory block S2, the memory block S3 of three formed objects, and the data that store these three memory blocks is identical.The data interaction of three memory blocks needs controller (CPU) to control.Above-mentioned three memory blocks are being carried out upgrading interruption because of unscheduled event in the data updating process; Again after three memory blocks being powered on, read successively the data of storage in memory block S1 and the memory block S2, if the data of memory block S1 are identical with the data of memory block S2, then take the data of memory block S1 as valid data VD, and the data in the S3 of memory block are carried out consistent update, otherwise take the data of memory block S3 as valid data VD, and the data in memory block S1, the memory block S2 are carried out consistent update.Memory block S1, memory block S2, memory block S3 are to the processing procedure of data, and be identical with described data storage and update method, this tired stating.
Above-mentioned explanation illustrates and has described the preferred embodiments of the present invention, as previously mentioned, be to be understood that the present invention is not limited to the disclosed form of this paper, should not regard the eliminating to other embodiment as, and can be used for various other combinations, modification and environment, and can in invention contemplated scope described herein, change by technology or the knowledge of above-mentioned instruction or association area.And the change that those skilled in the art carry out and variation do not break away from the spirit and scope of the present invention, then all should be in the protection domain of claims of the present invention.