Disclosure of Invention
In view of the above, the present invention provides a data storage method, a data recovery method and a data recovery device, which are used to store data by storing an offset value in a timestamp and obtain data by recovering the offset value. The technical scheme is as follows:
the invention provides a data storage method, which comprises the following steps:
acquiring the ith timestamp in an original timestamp sequence, wherein i is any number from 2 to n, and n is the total number of timestamps in the original timestamp sequence;
if the relation between the ith timestamp and the (i-1) th timestamp is a continuous relation and the ith timestamp is not the nth timestamp, adding 1 to the i and returning to execute the step of acquiring the ith timestamp in the original timestamp sequence;
and if the relation between the ith timestamp and the (i-1) th timestamp is a continuous relation and the ith timestamp is the nth timestamp, storing the offset values and the number of the stored offset values of the 1 st timestamp, the 2 nd timestamp and the nth timestamp in the original timestamp sequence.
Preferably, the method further comprises:
if the relation between the ith timestamp and the (i-1) th timestamp is a discontinuous relation, and the ith timestamp is the nth timestamp, independently storing the ith timestamp;
if the relation between the ith timestamp and the (i-1) th timestamp is a discontinuous relation and the ith timestamp is not the nth timestamp, determining the ith timestamp as a new 1 st timestamp in the original timestamp sequence, adding 1 to i, and returning to execute the step of obtaining the ith timestamp in the original timestamp sequence;
storing the 1 st timestamp to the i-1 st timestamp in the original timestamp sequence based on a relationship between timestamps.
Preferably, the storing the 1 st timestamp to the i-1 st timestamp in the original timestamp sequence based on the relationship between timestamps includes:
if the value of i is equal to 2, independently storing the 1 st time stamp in the original time stamp sequence;
if the value of i is greater than 2, if a continuous time stamp sequence composed of time stamps which are in a continuous relationship and adjacent to each other exists in the original time stamp sequence, storing the 1 st time stamp in the continuous time stamp sequence, storing the deviation value and the number of the stored deviation value from the 2 nd time stamp to the m th time stamp, wherein m-1 is the number of the deviation values in the continuous time stamp sequence, and if the relationship between the jth time stamp and the jth-1 time stamp in the original time stamp sequence is a discontinuous relationship and the relationship between the jth time stamp and the (j + 1) th time stamp is a discontinuous relationship, separately storing the jth time stamp in the original time stamp sequence.
Preferably, the storing offset values and the number of stored offset values of the 1 st timestamp, the 2 nd timestamp to the nth timestamp in the original timestamp sequence includes:
storing the 1 st time stamp, the 2 nd time stamp to the nth time stamp and the deviation value number into the continuous time stamp sequence according to the sequence of the 1 st time stamp to the nth time stamp in the original time stamp sequence;
the deviation value of the xth timestamp from the 2 nd timestamp to the nth timestamp is as follows: an offset value between the xth timestamp and the (x-1) th timestamp, or an offset value between the xth timestamp and the (1) th timestamp, wherein x is any number from 2 to n.
Preferably, the 1 st bit in the continuous time stamp sequence is a value of an identifier, and the value of the identifier is used to indicate that the relationships between the time stamps stored in the continuous time stamp sequence are all continuous relationships.
Preferably, the method further comprises: storing the sampling intervals of the original sequence of time stamps in the sequence of consecutive time stamps.
The invention provides a data reduction method, which comprises the following steps:
acquiring an identifier in a time stamp sequence, wherein the time stamp sequence is a sequence obtained by processing an original time stamp sequence based on the method of any one of claims 1 to 6;
if the value of the identifier in the timestamp sequence indicates that the timestamp sequence is a continuous timestamp sequence, acquiring fields which represent the 1 st timestamp, represent the deviation values of the 2 nd timestamp to the e nd timestamp and represent the number of the deviation values in the continuous timestamp sequence, and acquiring the 1 st timestamp to the e th timestamp based on the fields which represent the 1 st timestamp, represent the deviation values of the 2 nd timestamp to the e nd timestamp and represent the number of the deviation values, wherein e-1 is the number of the deviation values recorded by the continuous timestamp sequence;
and if the value of the identifier in the time stamp sequence indicates that the time stamp sequence is the independent time stamp sequence, calculating to obtain the time stamp recorded in the independent time stamp sequence.
The present invention provides a data storage device, the device comprising:
the first acquisition module is used for acquiring the ith timestamp in the original timestamp sequence, wherein i is any number from 2 to n, and n is the total number of timestamps in the original timestamp sequence;
a first return execution module, configured to add 1 to i and trigger the first obtaining module if a relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is not the nth timestamp;
and the first storage module is used for storing the 1 st timestamp, the deviation values from the 2 nd timestamp to the nth timestamp and the number of the stored deviation values in the original timestamp sequence if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is the nth timestamp.
Preferably, the apparatus further comprises:
a second storage module, configured to store an ith timestamp separately if a relationship between the ith timestamp and an (i-1) th timestamp is a discontinuous relationship and the ith timestamp is an nth timestamp;
a second return execution module, configured to determine, if the relationship between the ith timestamp and the (i-1) th timestamp is a discontinuous relationship and the ith timestamp is not the nth timestamp, that the ith timestamp is a new 1 st timestamp in the original timestamp sequence, add 1 to i, and trigger the first obtaining module;
and the third storage module is used for storing the 1 st timestamp to the (i-1) th timestamp in the original timestamp sequence based on the relation between the timestamps.
The present invention provides a data reduction apparatus, the apparatus comprising:
a second obtaining module, configured to obtain an identifier in a time stamp sequence, where the time stamp sequence is a sequence obtained by processing an original time stamp sequence based on the apparatus of any one of claims 8 to 9;
a first restoring module, configured to, if a value of an identifier in the timestamp sequence indicates that the timestamp sequence is a continuous timestamp sequence, obtain fields indicating a 1 st timestamp, an offset value indicating each of a 2 nd timestamp to an e th timestamp, and a number of the offset values in the continuous timestamp sequence, and obtain the 1 st timestamp to the e th timestamp based on the fields indicating the 1 st timestamp, the offset value indicating each of the 2 nd timestamp to the e th timestamp, and the number of the offset values, where e-1 is the number of the offset values recorded by the continuous timestamp sequence;
and the second restoring module is used for calculating the time stamp recorded in the independent time stamp sequence if the value of the identifier in the time stamp sequence indicates that the time stamp sequence is the independent time stamp sequence.
Known from the technical scheme, by acquiring the ith timestamp in the original timestamp sequence, if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is not the nth timestamp, adding 1 to i and returning to acquire the ith timestamp in the original timestamp sequence, if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is the nth timestamp, storing the 1 st timestamp in the original timestamp sequence, storing the offset values and the stored offset values of the 2 nd timestamp to the nth timestamp respectively, and restoring the unique timestamp corresponding to each offset value through the offset values, thereby reducing the occupation of a storage space by storing the offset values, and thus, when the offset values are stored, discarding the offset values is not required, and each time stamp in the original time stamp sequence can be accurately restored by storing the deviation value, so that the integrity and the authenticity of the time stamp are improved.
Detailed Description
Because real-time data in a plurality of fields, such as the field of industrial control, are generated by sampling by a collector at regular time, timestamps corresponding to the real-time data often increase regularly, and as a result, the timestamps corresponding to the real-time data theoretically conform to the following characteristics:
t1, t2 ═ t1 +/Δ t, t3 ═ t2 +/Δ t, as.. tn ═ tn-1 +/Δ t, where Δ t is the sampling interval, thus summarizing the theoretical rule followed between two adjacent timestamps in a sequence of timestamps consisting of a plurality of timestamps as: tn-1 +. DELTA.t (n-2, 3.... 9.).
In practice, due to the acquisition accuracy of the acquirer and other various reasons, each timestamp may have a certain degree of deviation, and the values of the timestamps in the timestamp sequence are as follows: t1+ d1, t2 ═ t1 +/Δ t + d2, t3 ═ t2 +/Δ t + d3,.. 9., tn ═ tn-1 +/Δ t + dn (n > -2), so that the law that is followed on the basis of theoretical laws between two adjacent timestamps in a sequence of timestamps is:
tn-1 +. DELTA.t + dn (n > -2). Wherein d2, d 3.. and dn are deviation values, and if the collector continuously collects, the value of delta t + dn fluctuates above and below the sampling interval delta t.
Assuming that each timestamp is represented by int64 when storing the timestamp sequence, each timestamp occupies 8 bytes, which results in a large storage space occupied by the timestamp sequence, and the inventor has observed that the offset value is used to replace the timestamp by taking advantage of the above-mentioned rule of tn-1 +. Δ t + dn (n > -2), because: compared with the timestamp, the offset value is far smaller than the timestamp, so that a smaller storage space can be used for storing the offset value, for example, but not limited to, 2 bytes are used for storing, and the storage space occupied by the timestamp sequence is greatly reduced.
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a flowchart of a data storage method provided by an embodiment of the present invention is shown, for reducing a storage space occupied by a time stamp sequence, where the method may include the following steps:
s101: and acquiring the ith timestamp in the original timestamp sequence, wherein i is any number from 2 to n, and n is the total number of timestamps in the original timestamp sequence. It can be understood that: the sequence of each timestamp in the original timestamp sequence is from 1 to n, but in the actual storage process, each timestamp can be sequentially acquired from the 2 nd timestamp of the original timestamp sequence until the last timestamp of the original timestamp sequence, and any timestamp between the 2 nd timestamp and the last timestamp can be acquired only once, and the subsequent steps are executed for each timestamp. The reason why the acquisition can be started from the 2 nd timestamp is that the acquisition is started from the 2 nd timestamp because the acquisition is based on the relationship between the ith timestamp and the (i-1) th timestamp in the subsequent storage, the 1 st timestamp is the first timestamp in the original timestamp sequence, the timestamps before the 1 st timestamp do not exist for the 1 st timestamp, and the storage mode of the 1 st timestamp can also be determined through the relationship between the 1 st timestamp and the 2 nd timestamp.
If the original timestamp sequence contains 10 timestamps, the timestamps are sequentially acquired from the 2 nd timestamp until the 10 th timestamp is acquired, the acquisition is finished, and the following steps are executed on the currently acquired timestamp every time one timestamp is acquired so as to judge the relationship between the currently acquired timestamp and the previous timestamp adjacent to the currently acquired timestamp and determine how to store the timestamp based on the relationship.
S102: and if the relation between the ith timestamp and the (i-1) th timestamp is a continuous relation and the ith timestamp is not the nth timestamp, adding 1 to the ith timestamp, and returning to execute the step of acquiring the ith timestamp in the original timestamp sequence.
In this embodiment, one possible way to determine the relationship between the ith timestamp and the (i-1) th timestamp is to: obtaining an ith time stamp and an ith-1 time stamp, obtaining an offset value (for convenience of description, marked as an ith offset value) between the ith time stamp and the ith-1 time stamp based on the ith time stamp and the ith-1 time stamp, if the ith offset value has continuity, determining that the relationship between the ith time stamp and the ith-1 time stamp is a continuous relationship, and if the ith offset value does not have continuity, determining that the relationship between the ith time stamp and the ith-1 time stamp is a discontinuous relationship.
One possible way to determine whether the ith deviation value has continuity is: and judging whether the ith deviation value is within a threshold range, if the ith deviation value is within the threshold range, the ith deviation value has continuity, if the ith deviation value is not within the threshold range, the ith deviation value does not have continuity, and the threshold range can be but is not limited to [ -32768, +32767], so that if the ith deviation value is within [ -32768, +32767], the ith deviation value is confirmed to have continuity, and otherwise, the ith deviation value does not have continuity.
One possible way to determine that the ith timestamp is not the nth timestamp is to: and obtaining the value of i, obtaining the total number n of the timestamps, and judging whether i is greater than or equal to n, wherein if i is greater than or equal to n, the ith timestamp is the nth timestamp, and if i is less than n, the ith timestamp is not the nth timestamp.
It should be noted that: adding 1 to i and returning to execute the step of acquiring the ith timestamp in the original timestamp sequence, namely: and if the relation between the ith timestamp and the (i-1) th timestamp is a continuous relation, returning to obtain the (i + 1) th timestamp in the original timestamp sequence, and if the relation between the (5) th timestamp and the (4) th timestamp is a continuous relation, continuously obtaining the (6) th timestamp in the original timestamp sequence.
S103: and if the relation between the ith timestamp and the (i-1) th timestamp is a continuous relation and the ith timestamp is the nth timestamp, storing the 1 st timestamp in the original timestamp sequence, storing the deviation values of the 2 nd timestamp to the nth timestamp and storing the number of the deviation values.
In this embodiment, one possible way to store the offset values and the number of stored offset values of the 1 st timestamp, the 2 nd timestamp to the nth timestamp in the original timestamp sequence is as follows: and storing the 1 st time stamp, the 2 nd time stamp to the nth time stamp and the deviation value number into the continuous time stamp sequence according to the sequence of the 1 st time stamp to the nth time stamp in the original time stamp sequence.
That is, with respect to the original time stamp sequence, each memory cell in the original time stamp sequence stores one time stamp, while the 1 st memory cell in the continuous time stamp sequence stores the 1 st time stamp, and the other memory cells store the offset value of the time stamp, and the content stored by each memory cell in the continuous time stamp sequence is still in the order of the 1 st to nth time stamps in the original time stamp sequence.
Wherein the deviation value of the xth timestamp from the 2 nd timestamp to the nth timestamp is: an offset value between the xth timestamp and the (x-1) th timestamp, or an offset value between the xth timestamp and the (1) th timestamp, wherein x is any number from 2 to n. That is, each timestamp from the 2 nd timestamp to the nth timestamp has 1 corresponding offset value, such as the offset values d2, d3, a...... and dn obtained from the above tn-1 +. DELTA.t + dn (n > -2) and stored in sequence in the sequence of consecutive timestamps based on the sequence of d2, d3, a.... and dn, and the offset values from the tn-1 +. DELTA.t + dn (n > -2) are known to be offset values between the x-th timestamp and the x-1 st timestamp, although other offset values from other timestamps with respect to the 1 st timestamp, such as the offset values between the x-th timestamp and the 1 st timestamp, may be calculated with the 1 st timestamp as a reference, or calculated with other timestamps as a reference, this embodiment is not illustrated.
It should be noted that: when the deviation values of the 1 st time stamp, the 2 nd time stamp and the nth time stamp in the original time stamp sequence are stored, the number of the deviation values also needs to be stored, so that the deviation values stored in the continuous time stamp sequence can be determined through the number of the deviation values when the data is restored, if the time stamps t2 to t5 in the original time stamp sequence are in a continuous relation, the deviation values of the t2 to t5 in one continuous time stamp sequence are stored, and meanwhile, the number of the deviation values in the continuous time stamp sequence is stored to the continuous time stamp sequence, and the value of the number of the deviation values in the current continuous time stamp sequence is 4.
To facilitate determining whether current data is data in a sequence of consecutive time stamps during data recovery, the consecutive time stamp sequence may be marked by means of an identifier, for example, the 1 st bit in the consecutive time stamp sequence is the value of the identifier, the value of the identifier is used to indicate that the relation between the timestamps stored in the sequence of consecutive timestamps is a consecutive relation, for example, when the value of the identifier is 1, indicating that it is a sequence of consecutive time stamps and the relationship between the time stamps stored in the sequence of consecutive time stamps is a consecutive relationship, the time stamps can be restored for the data stored in the 2 nd to nth memory cells during data restoration in a manner of tn-1 +. DELTA.t + dn (n > -2), where dn is an offset value corresponding to the nth time stamp stored in the nth memory cell and Δ t is a sampling interval. The bytes of the memory cells storing the offset value may be determined according to the offset value, and if the offset value needs to occupy 2 bytes or 4 bytes, 2 bytes or 4 bytes may be allocated to the memory cells to store the offset value, and the bytes allocated to the memory cells are not limited herein as long as they are smaller than the bytes occupied by the time stamps in the original time stamp sequence.
And as can be seen from tn-1 +. DELTA.t + dn (n > -2), DELTA.t is required for the reduction, for which purpose a sampling interval can be stored in the sequence of consecutive time stamps, which sampling interval can be stored in the last memory location of the sequence of consecutive time stamps, i.e. by adding one memory location to the original sequence of time stamps, as shown in Table 1.
TABLE 1 storage of a sequence of consecutive time stamps
Of course, other storage manners may also be adopted, such as storing the sampling interval between the offset value corresponding to the 1 st timestamp and the offset value corresponding to the 2 nd timestamp, which is not illustrated in this embodiment, or interacting the sampling interval in a pre-interaction manner, so as to perform data recovery. For the number of the offset values, the number of the offset values may be stored between the offset values corresponding to the 1 st timestamp and the 2 nd timestamp, or stored in other locations.
Known from the technical scheme, by acquiring the ith timestamp in the original timestamp sequence, if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is not the nth timestamp, adding 1 to i and returning to acquire the ith timestamp in the original timestamp sequence, if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is the nth timestamp, storing the 1 st timestamp in the original timestamp sequence, storing the offset values and the stored offset values of the 2 nd timestamp to the nth timestamp respectively, and restoring the unique timestamp corresponding to each offset value through the offset values, thereby reducing the occupation of a storage space by storing the offset values, and thus, when the offset values are stored, discarding the offset values is not required, and each time stamp in the original time stamp sequence can be accurately restored by storing the deviation value, so that the integrity and the authenticity of the time stamp are improved.
In contrast, if the relationship between the ith timestamp and the (i-1) th timestamp is a discontinuous relationship, the ith timestamp also needs to be stored, so this embodiment provides a flowchart of another data storage method, which explains a storage manner when the relationship between the ith timestamp and the (i-1) th timestamp is a discontinuous relationship, and the data storage method may include the following steps based on fig. 1:
s104: if the relation between the ith timestamp and the (i-1) th timestamp is a discontinuous relation, and the ith timestamp is the nth timestamp, the ith timestamp is separately stored.
The step S102 is performed in the same manner and in the same principle as the step S102, and is not described herein again. But differs from step S102 in that: if the relationship between two adjacent timestamps is a discontinuous relationship and the ith timestamp is the nth timestamp, the ith timestamp is stored separately, for example, the ith timestamp is stored in an independent timestamp sequence, and the independent timestamp sequence may store only one timestamp having a discontinuous relationship with the adjacent timestamps or store a plurality of timestamps having a discontinuous relationship with the adjacent timestamps.
Corresponding to the continuous time stamp sequence, for the independent time stamp sequence, a value of an identifier also needs to be configured, for example, a value of the identifier is recorded at the 1 st bit of the independent time stamp sequence, the value of the identifier is different from the value of the identifier in the continuous time stamp sequence, for example, the value of the identifier in the independent time stamp sequence is 0, so as to indicate that the relation between each stored time stamp in the independent time stamp sequence and other time stamps is a discontinuous relation.
Here, it should be noted that: if an original timestamp sequence is obtained as at least one continuous timestamp sequence and at least one independent timestamp sequence, and each independent timestamp sequence only stores one timestamp, when the continuous timestamp sequence and the independent timestamp sequence are stored, it needs to be stored according to the ordering of the timestamps in the original timestamp sequence in the continuous timestamp sequence and the independent timestamp sequence, for example, the original timestamp sequence is composed of 10 timestamps, where the 1 st timestamp to the 3 rd timestamp form one continuous timestamp sequence (described as continuous timestamp sequence 1), the 4 th timestamp is in one independent timestamp sequence (described as independent timestamp sequence 1), the 5 th timestamp sequence to the 10 th timestamp form one continuous timestamp sequence (described as continuous timestamp sequence 2, then the positional relationship of these three time stamp sequences at the time of storage is: the continuous time stamp sequence 1, the independent time stamp sequence 1 and the continuous time stamp sequence 2 can sequentially restore data in the three time stamp sequences during restoration, and the restored time stamps are ordered as follows: the 1 st, 2 nd, 10 th timestamps have the same ordering as the timestamps in the original sequence of timestamps.
If a plurality of timestamps are stored in one independent timestamp sequence, in order to make the sequence of the restored timestamps the same as the sequence of the timestamps in the original timestamp sequence, the sequences of the timestamps and the offset values in the original timestamp sequence need to be stored in the continuous timestamp sequence and the independent timestamp sequence, so that the restored timestamps can be arranged according to the sequences during restoration.
S105: and if the relation between the ith timestamp and the (i-1) th timestamp is a discontinuous relation and the ith timestamp is not the nth timestamp, determining the ith timestamp as a new 1 st timestamp in the original timestamp sequence, adding 1 to i, and returning to execute the step of acquiring the ith timestamp in the original timestamp sequence.
That is, if the relationship between a timestamp in the original timestamp sequence and the previous timestamp is a discontinuous relationship, the timestamp is used as the new 1 st timestamp in the original timestamp sequence, then the other timestamps that are located after the new 1 st timestamp in the original timestamp sequence are sequentially acquired from the new 1 st timestamp, and the relationship between the new 1 st timestamp and the other timestamps that are located after the new 1 st timestamp is determined and stored based on the relationship.
For example, the relationship between the 5 th timestamp and the 4 th timestamp in the original timestamp sequence is a discontinuous relationship, and the 5 th timestamp is not the nth timestamp (i.e., the last timestamp), then the 5 th timestamp is taken as the new 1 st timestamp, and the other timestamps after the new 1 st timestamp, i.e., the 6 th timestamp to the nth timestamp, are continuously and sequentially acquired.
S106: the 1 st time stamp through the (i-1) th time stamp in the original time stamp sequence are stored based on the relationship between the time stamps.
In this embodiment, the storage of the 1 st timestamp to the i-1 st timestamp in the original timestamp sequence based on the relationship between timestamps needs to be determined based on the value of i, specifically: if the value of i is equal to 2, the 1 st timestamp in the original timestamp sequence is stored separately.
If the value of i is greater than 2, if a continuous time stamp sequence formed by mutually adjacent time stamps with a continuous relation exists in the original time stamp sequence, storing the 1 st time stamp in the continuous time stamp sequence, storing the deviation value from the 2 nd time stamp to the m th time stamp and the number of the stored deviation values, wherein m-1 is the number of the deviation values in the continuous time stamp sequence.
That is, the value of i is greater than 2, and if the relationship between a plurality of timestamps that are consecutive to each other in the original timestamp sequence is a consecutive relationship, the plurality of timestamps are considered to form a consecutive timestamp sequence. For example, in the 1 st to i-1 th timestamps of the original timestamp sequence, the relationship between any two adjacent timestamps is a continuous relationship, and a continuous timestamp sequence is formed according to the j to j + a timestamps (where a is a natural number greater than or equal to 1), then for this continuous timestamp sequence, the j timestamp is used as the 1 st timestamp, the offset values and the stored offset value numbers of the other timestamps are stored in the continuous timestamp sequence, and for the obtaining manner of the offset values of the other timestamps, please refer to the description in the above method embodiment.
If the value of i is greater than 2, if the relationship between the jth timestamp and the jth-1 timestamp in the original timestamp sequence is a discontinuous relationship and the relationship between the jth timestamp and the (j + 1) th timestamp in the original timestamp sequence is a discontinuous relationship, the jth timestamp in the original timestamp sequence is separately stored. For example, the jth timestamp may be stored in an independent timestamp sequence, and for the description of the independent timestamp sequence, refer to the related description in the above method embodiment.
The following describes the method shown in fig. 1 and 2, taking an example that an original time stamp sequence includes 10 time stamps: the following relationship exists between the 10 timestamps:
the first relationship is: if the relation between any two adjacent timestamps in the 10 timestamps is a continuous relation, the 10 timestamps are stored in a continuous timestamp sequence in the following way: and storing the 1 st time stamp in the 10 time stamps, storing the offset values of other time stamps and storing the number of the offset values in the continuous time stamp sequence.
The second relationship is: the relation between the 10 th timestamp and/or the 1 st timestamp in the 10 timestamps and the adjacent timestamps is a discontinuous relation, and the relation between other timestamps is a continuous relation, then the 10 th timestamp and/or the 1 st timestamp is stored separately, and other timestamps can be stored in a continuous timestamp sequence, and the storage mode is as follows: if the stored timestamps of the 1 st sequence among the timestamps and the offset values of the other sequences, for example, the other timestamps are from the 2 nd timestamp to the 9 th timestamp, the offset values of the 2 nd timestamp, the 3 rd timestamp to the 9 th timestamp are stored in the continuous timestamp sequence, and the number of the offset values is stored.
The third relationship is: the relation between the other timestamps except the 10 th timestamp and the 1 st timestamp among the 10 timestamps and the adjacent timestamps is a discontinuous relation, for example, the relation between the 3 rd timestamp and the 8 th timestamp among the 10 timestamps and the adjacent timestamps is a discontinuous relation, and the relation between the other adjacent timestamps is a continuous relation, then the three part of the timestamps divided by the 3 rd timestamp and the 8 th timestamp are respectively regarded as a continuous timestamp sequence, i.e. the 1 st timestamp and the 2 nd timestamp constitute a continuous timestamp sequence, the 4 th timestamp to the 7 th timestamp constitute a continuous timestamp sequence, the 9 th timestamp and the 10 th timestamp constitute a continuous timestamp sequence, and for the three continuous timestamp sequences, any continuous timestamp sequence is stored according to the description in the second relation, and storing the 3 rd time stamp and the 8 th time stamp in independent time stamp sequences, for example, storing the 3 rd time stamp and the 8 th time stamp in an independent time stamp sequence respectively, and storing the number of deviation values corresponding to each continuous time stamp sequence.
As can be seen from the foregoing technical solution, if the relationship between the ith timestamp and the (i-1) th timestamp is a discontinuous relationship and the ith timestamp is the nth timestamp, the ith timestamp is separately stored, if the relationship between the ith timestamp and the (i-1) th timestamp is not a continuous relationship and the ith timestamp is not the nth timestamp, the (1) th timestamp to the (i-1) th timestamp in the original timestamp sequence can be stored based on the relationship between the timestamps, and there is a case where an offset value of some timestamps is stored when the offset value is stored based on the relationship between the timestamps, so that the storage space occupied by the timestamps can be reduced, the timestamps are not lost, and the integrity and the authenticity of the timestamps are improved.
Referring to fig. 3, a flowchart of a data restoring method according to an embodiment of the present invention is shown, configured to restore timestamps in a timestamp sequence, where in detail, the data restoring method shown in fig. 3 may include the following steps:
s201: the identifier in the time stamp sequence is acquired, wherein the time stamp sequence is a sequence obtained by processing the original time stamp sequence based on the data storage method, and the identifier in the time stamp sequence can be acquired based on the setting of the identifier position by the data storage method, and the identifier can be acquired from the 1 st bit by setting the 1 st bit in the sequence as the identifier by the data storage method.
S202: if the value of the identifier in the timestamp sequence indicates that the timestamp sequence is a continuous timestamp sequence, acquiring fields which represent the 1 st timestamp, represent the deviation values from the 2 nd timestamp to the e nd timestamp and represent the number of the deviation values in the continuous timestamp sequence, and acquiring the 1 st timestamp to the e th timestamp based on the fields which represent the 1 st timestamp, represent the deviation values from the 2 nd timestamp to the e nd timestamp and represent the number of the deviation values, wherein e-1 is the number of the deviation values recorded by the continuous timestamp sequence.
One possible way in which the value of the identifier in the timestamp sequence indicates that the timestamp sequence is a continuous timestamp sequence is: based on the identifier in the timestamp sequence, the value of the identifier is obtained, if the value of the identifier meets a first threshold, the timestamp sequence is a continuous timestamp sequence, if the first threshold may be 1, if the value of the identifier is 1, the timestamp sequence is a continuous timestamp sequence, the first threshold may be determined according to practical application, and the value of the first threshold is not limited in this embodiment.
If the time stamp sequence is a continuous time stamp sequence, acquiring fields which are stored in the continuous time stamp sequence and represent the 1 st time stamp, the 2 nd to e th time stamps and offset values respectively, and acquiring data from the fields to restore the data, wherein the 1 st time stamp is acquired by N-ary operation, the 1 st time stamp is restored by binary operation if the continuous time stamp sequence is stored in binary, and the 2 nd time stamp and the e th time stamp are restored based on the offset values and tn-1+ [ delta ] t + dn (N > < 2).
S203: and if the value of the identifier in the time stamp sequence indicates that the time stamp sequence is the independent time stamp sequence, calculating to obtain the time stamp recorded in the independent time stamp sequence.
One possible way in which the value of the identifier in the timestamp sequence indicates that the timestamp sequence is an independent timestamp sequence is: based on the identifier in the timestamp sequence, the value of the identifier is obtained, if the value of the identifier meets a second threshold, the timestamp sequence is an independent timestamp sequence, if the second threshold is 0, if the value of the identifier is 0, the timestamp sequence is an independent timestamp sequence, the second threshold may be determined according to practical application, and the value of the second threshold is not limited in this embodiment.
One possible way to calculate the timestamps in the independent timestamp sequences is to: and restoring the timestamp of the data stored in any storage unit in the independent timestamp sequence through N-system operation, and restoring the timestamp through binary operation if the independent timestamp sequence adopts binary storage.
According to the technical scheme, if the value of the identifier in the time stamp sequence indicates that the time stamp sequence is a continuous time stamp sequence, the time stamp sequence is obtained by processing the original time stamp sequence through the data storage method, the fields indicating the 1 st time stamp, the deviation values from the 2 nd time stamp to the e nd time stamp and the number of the deviation values in the continuous time stamp sequence are obtained, the 1 st time stamp to the e th time stamp are obtained based on the fields indicating the 1 st time stamp, the deviation values from the 2 nd time stamp to the e nd time stamp and the number of the deviation values, and the time stamps recorded in the independent time stamp sequence are obtained by calculation if the value of the identifier in the time stamp sequence indicates that the time stamp sequence is an independent time stamp sequence, so that the time stamps recorded in the time stamp sequence are restored.
While, for purposes of simplicity of explanation, the foregoing method embodiments have been described as a series of acts or combination of acts, it will be appreciated by those skilled in the art that the present invention is not limited by the illustrated ordering of acts, as some steps may occur in other orders or concurrently with other steps in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
Corresponding to the above method embodiments, an embodiment of the present invention provides a data storage device, whose schematic structural diagram is shown in fig. 4, and the data storage device may include: a first obtaining module 11, a first return execution module 12 and a first storage module 13.
The first obtaining module 11 is configured to obtain an ith timestamp in the original timestamp sequence, where i is any number from 2 to n, and n is a total number of timestamps in the original timestamp sequence. It can be understood that: the sequence of the timestamps in the original timestamp sequence is from 1 to n, but in the actual storage process, the timestamps may be sequentially obtained from the 2 nd timestamp of the original timestamp sequence to the last timestamp of the original timestamp sequence, and any timestamp between the 2 nd timestamp and the last timestamp is obtained only once, and each timestamp is processed, so the reason for obtaining from the 2 nd timestamp is described in the method embodiment.
The first return execution module 12 is configured to add 1 to i and trigger the first obtaining module 11 to continue to obtain other timestamps in the original timestamp sequence if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is not the nth timestamp.
In this embodiment, one possible way for the first return execution module 12 to determine the relationship between the ith timestamp and the (i-1) th timestamp is as follows: obtaining an ith time stamp and an ith-1 time stamp, obtaining an offset value (for convenience of description, marked as an ith offset value) between the ith time stamp and the ith-1 time stamp based on the ith time stamp and the ith-1 time stamp, if the ith offset value has continuity, determining that the relationship between the ith time stamp and the ith-1 time stamp is a continuous relationship, and if the ith offset value does not have continuity, determining that the relationship between the ith time stamp and the ith-1 time stamp is a discontinuous relationship. For the determination of whether the ith deviation value has continuity and the determination of whether the ith timestamp is the nth timestamp, please refer to the method embodiment, which will not be described further.
A first storing module 13, configured to store the 1 st timestamp, the offset value from the 2 nd timestamp to the nth timestamp, and the number of stored offset values in the original timestamp sequence if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is the nth timestamp.
In this embodiment, one possible way to store the offset values and the number of stored offset values of the 1 st timestamp, the 2 nd timestamp to the nth timestamp in the original timestamp sequence is as follows: and storing the 1 st time stamp, the 2 nd time stamp to the nth time stamp and the deviation value number into the continuous time stamp sequence according to the sequence of the 1 st time stamp to the nth time stamp in the original time stamp sequence.
That is, with respect to the original time stamp sequence, each memory cell in the original time stamp sequence stores one time stamp, while the 1 st memory cell in the continuous time stamp sequence stores the 1 st time stamp, and the other memory cells store the offset value of the time stamp, and the content stored by each memory cell in the continuous time stamp sequence is still in the order of the 1 st to nth time stamps in the original time stamp sequence, and the number of offset values is stored in one memory cell in the continuous time stamp sequence.
Wherein the deviation value of the xth timestamp from the 2 nd timestamp to the nth timestamp is: an offset value between the xth timestamp and the xth-1 timestamp, or an offset value between the xth timestamp and the 1 st timestamp, where x is any number from 2 to n, is described with reference to the method embodiment, which is not described again.
In addition, in order to facilitate determining whether current data is data in a continuous time stamp sequence or not during data restoration, the continuous time stamp sequence may be marked by an identifier, for example, the 1 st bit in the continuous time stamp sequence is a value of the identifier, the value of the identifier is used to indicate that all relationships between time stamps stored in the continuous time stamp sequence are continuous relationships, for example, when the value of the identifier is 1, it indicates that the continuous time stamp sequence and all relationships between time stamps stored in the continuous time stamp sequence are continuous relationships, a time stamp may be restored for data stored in the 2 nd to nth storage units in a manner of tn-1 +/Δ t + dn (n >) 2, dn is an offset value corresponding to the nth time stamp stored in the nth storage unit, Δ t is a sampling interval, the sampling interval may also be stored in a sequence of consecutive time stamps, see the description of the method embodiment for storing the offset value and the sampling interval.
Known from the technical scheme, by acquiring the ith timestamp in the original timestamp sequence, if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is not the nth timestamp, adding 1 to i and returning to acquire the ith timestamp in the original timestamp sequence, if the relationship between the ith timestamp and the (i-1) th timestamp is a continuous relationship and the ith timestamp is the nth timestamp, storing the 1 st timestamp in the original timestamp sequence, storing the offset values and the stored offset values of the 2 nd timestamp to the nth timestamp respectively, and restoring the unique timestamp corresponding to each offset value through the offset values, thereby reducing the occupation of a storage space by storing the offset values, and thus, when the offset values are stored, discarding the offset values is not required, and each time stamp in the original time stamp sequence can be accurately restored by storing the deviation value, so that the integrity and the authenticity of the time stamp are improved.
In contrast, if the relationship between the ith timestamp and the (i-1) th timestamp is a discontinuous relationship, the ith timestamp also needs to be stored, so this embodiment provides another structural schematic diagram of a data storage device, which explains a storage manner when the relationship between the ith timestamp and the (i-1) th timestamp is a discontinuous relationship, and the data storage device may include, on the basis of fig. 4: a second storage module 14, a second return execution module 15 and a third storage module 16, as shown in fig. 5.
A second storing module 14, configured to store the ith timestamp separately if the relationship between the ith timestamp and the (i-1) th timestamp is a discontinuous relationship, and the ith timestamp is an nth timestamp, for example, store the ith timestamp in an independent timestamp sequence.
Please refer to the description in the above method embodiment, which will not be further described herein, wherein the relationship between the ith timestamp and the (i-1) th timestamp is determined, and it is determined that the ith timestamp is not the nth timestamp.
Corresponding to the continuous time stamp sequence, for the independent time stamp sequence, a value of an identifier also needs to be configured, for example, a value of the identifier is recorded at the 1 st bit of the independent time stamp sequence, the value of the identifier is different from the value of the identifier in the continuous time stamp sequence, for example, the value of the identifier in the independent time stamp sequence is 0, so as to indicate that the relation between each stored time stamp in the independent time stamp sequence and other time stamps is a discontinuous relation.
Here, it should be noted that: if an original timestamp sequence is obtained as at least one continuous timestamp sequence and at least one independent timestamp sequence, and each independent timestamp sequence only stores one timestamp, when the continuous timestamp sequence and the independent timestamp sequence are stored, it needs to be stored according to the ordering of the timestamps in the original timestamp sequence in the continuous timestamp sequence and the independent timestamp sequence, for example, the original timestamp sequence is composed of 10 timestamps, where the 1 st timestamp to the 3 rd timestamp form one continuous timestamp sequence (described as continuous timestamp sequence 1), the 4 th timestamp is in one independent timestamp sequence (described as independent timestamp sequence 1), the 5 th timestamp sequence to the 10 th timestamp form one continuous timestamp sequence (described as continuous timestamp sequence 2, then the positional relationship of these three time stamp sequences at the time of storage is: the continuous time stamp sequence 1, the independent time stamp sequence 1 and the continuous time stamp sequence 2 can sequentially restore data in the three time stamp sequences during restoration, and the restored time stamps are ordered as follows: the 1 st, 2 nd, 10 th timestamps have the same ordering as the timestamps in the original sequence of timestamps.
If a plurality of timestamps are stored in one independent timestamp sequence, in order to make the sequence of the restored timestamps the same as the sequence of the timestamps in the original timestamp sequence, the sequences of the timestamps and the offset values in the original timestamp sequence need to be stored in the continuous timestamp sequence and the independent timestamp sequence, so that the restored timestamps can be arranged according to the sequences during restoration.
A second return execution module 15, configured to determine, if the relationship between the ith timestamp and the (i-1) th timestamp is a discontinuous relationship and the ith timestamp is not the nth timestamp, that the ith timestamp is the new 1 st timestamp in the original timestamp sequence, add 1 to i, and trigger the first obtaining module 11 to continue to obtain other timestamps in the original timestamp sequence.
That is, if the relationship between a timestamp in the original timestamp sequence and the previous timestamp is a discontinuous relationship, the timestamp is used as the new 1 st timestamp in the original timestamp sequence, then the other timestamps that are located after the new 1 st timestamp in the original timestamp sequence are sequentially acquired from the new 1 st timestamp, and the relationship between the new 1 st timestamp and the other timestamps that are located after the new 1 st timestamp is determined and stored based on the relationship.
For example, the relationship between the 5 th timestamp and the 4 th timestamp in the original timestamp sequence is a discontinuous relationship, and the 5 th timestamp is not the nth timestamp (i.e., the last timestamp), then the 5 th timestamp is taken as the new 1 st timestamp, and the other timestamps after the new 1 st timestamp, i.e., the 6 th timestamp to the nth timestamp, are continuously and sequentially acquired.
A third storage module 16, configured to store the 1 st timestamp to the i-1 st timestamp in the original timestamp sequence based on a relationship between timestamps.
In this embodiment, the storage of the 1 st timestamp to the i-1 st timestamp in the original timestamp sequence based on the relationship between timestamps needs to be determined based on the value of i, specifically: if the value of i is equal to 2, the 1 st timestamp in the original timestamp sequence is stored separately.
If the value of i is greater than 2, if a continuous time stamp sequence formed by mutually adjacent time stamps with a continuous relation exists in the original time stamp sequence, storing the 1 st time stamp in the continuous time stamp sequence, storing the deviation value from the 2 nd time stamp to the m th time stamp and the number of the stored deviation values, wherein m-1 is the number of the deviation values in the continuous time stamp sequence.
That is, the value of i is greater than 2, and if the relationship between a plurality of timestamps that are consecutive to each other in the original timestamp sequence is a consecutive relationship, the plurality of timestamps are considered to form a consecutive timestamp sequence. For example, in the 1 st to i-1 th timestamps of the original timestamp sequence, the relationship between any two adjacent timestamps is a continuous relationship, and a continuous timestamp sequence is formed according to the j to j + a timestamps (where a is a natural number greater than or equal to 1), then for this continuous timestamp sequence, the j timestamp is used as the 1 st timestamp, the offset values and the stored offset value numbers of the other timestamps are stored in the continuous timestamp sequence, and for the obtaining manner of the offset values of the other timestamps, please refer to the description in the above method embodiment.
If the value of i is greater than 2, if the relationship between the jth timestamp and the jth-1 timestamp in the original timestamp sequence is a discontinuous relationship and the relationship between the jth timestamp and the (j + 1) th timestamp in the original timestamp sequence is a discontinuous relationship, the jth timestamp in the original timestamp sequence is separately stored. For example, the jth timestamp may be stored in an independent timestamp sequence, and for the description of the independent timestamp sequence, refer to the related description in the above method embodiment. Specifically, please refer to the above method embodiments, which are not described herein again.
An embodiment of the present invention further provides a data recovery apparatus, a structure of which is shown in fig. 6, and the data recovery apparatus may include: a second obtaining module 21, a first restoring module 22 and a second restoring module 23.
The second obtaining module 21 is configured to obtain an identifier in a time stamp sequence, where the time stamp sequence is a sequence obtained by processing an original time stamp sequence based on the data storage device, and the identifier in the time stamp sequence can be obtained based on a setting of the data storage device to a location of the identifier, and the identifier can be obtained from the 1 st bit if the data storage device sets the 1 st bit in the sequence as the identifier.
A first restoring module 22, configured to, if a value of an identifier in the timestamp sequence indicates that the timestamp sequence is a continuous timestamp sequence, obtain fields indicating a 1 st timestamp, offset values indicating respective 2 nd to nth timestamps, and a number of the offset values in the continuous timestamp sequence, and obtain the 1 st to e-th timestamps based on the fields indicating the 1 st timestamp, the offset values indicating respective 2 nd to e-th timestamps, and the number of the offset values, where e-1 is the number of the offset values recorded by the continuous timestamp sequence.
One possible way in which the value of the identifier in the timestamp sequence indicates that the timestamp sequence is a continuous timestamp sequence is: based on the identifier in the timestamp sequence, the value of the identifier is obtained, if the value of the identifier meets a first threshold, the timestamp sequence is a continuous timestamp sequence, if the first threshold may be 1, if the value of the identifier is 1, the timestamp sequence is a continuous timestamp sequence, the first threshold may be determined according to practical application, and the value of the first threshold is not limited in this embodiment.
If the time stamp sequence is a continuous time stamp sequence, acquiring fields for storing the 1 st time stamp, the 2 nd to e th time stamps and the number of stored offset values, and acquiring data from the fields for restoring, wherein the fields are acquired by N-ary operation for the 1 st time stamp, the 1 st time stamp can be restored by binary operation if the continuous time stamp sequence is stored in binary, and the 2 nd and e-th time stamps can be restored based on the offset values and tn-1+ [ delta ] t + dn (N > [ 2 ]).
The second restoring module 23 is configured to calculate to obtain a timestamp recorded in the independent timestamp sequence if the value of the identifier in the timestamp sequence indicates that the timestamp sequence is the independent timestamp sequence. One possible way in which the value of the identifier in the timestamp sequence indicates that the timestamp sequence is an independent timestamp sequence is: based on the identifier in the timestamp sequence, the value of the identifier is obtained, if the value of the identifier meets a second threshold, the timestamp sequence is an independent timestamp sequence, if the second threshold is 0, if the value of the identifier is 0, the timestamp sequence is an independent timestamp sequence, the second threshold may be determined according to practical application, and the value of the second threshold is not limited in this embodiment.
One possible way to calculate the timestamps in the independent timestamp sequences is to: and restoring the timestamp of the data stored in any storage unit in the independent timestamp sequence through N-system operation, and restoring the timestamp through binary operation if the independent timestamp sequence adopts binary storage.
According to the technical scheme, if the value of the identifier in the time stamp sequence indicates that the time stamp sequence is a continuous time stamp sequence, the time stamp sequence is obtained by processing the original time stamp sequence through the data storage method, the fields indicating the 1 st time stamp, the deviation values from the 2 nd time stamp to the e nd time stamp and the number of the deviation values in the continuous time stamp sequence are obtained, the 1 st time stamp to the e th time stamp are obtained based on the fields indicating the 1 st time stamp, the deviation values from the 2 nd time stamp to the e nd time stamp and the number of the deviation values, and the time stamps recorded in the independent time stamp sequence are obtained by calculation if the value of the identifier in the time stamp sequence indicates that the time stamp sequence is an independent time stamp sequence, so that the time stamps recorded in the time stamp sequence are restored.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the device-like embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.