Data power-off storage method, device and electronic equipment
By setting the data area and index area for cyclic storage in the address area, and detecting the abnormality of the write index value in the index area after the system powered down, and determining the current write index value of the data area, the problem that traditional methods cannot achieve the continuous data powered down is solved, and the correct storage and recovery of data is achieved.
Patent Information
- Application Number
- CN202111205416.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-15
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2041-10-15
AI Technical Summary
Traditional data storage methods cannot determine the location of data storage after the system powered down, resulting in the inability to realize the powered down of data.
By setting the data area and the index area in the address area, the data area cyclically stores the data to be stored, and the index area cyclically stores the write index value of the data area. When the system is powered off and powered on again, it sequentially detects whether the write index value stored in the index area is abnormal, determines the current write index value of the data area based on the detection result, and stores the data to be stored in the data storage unit indicated by the write index value.
The data is continuously stored in power-down, ensuring that data can be stored and restored correctly when the system is powered down and re-powered.
Smart Images

Figure CN113934648B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data storage, and in particular relates to a method, device and electronic equipment for data storage after power failure. Background Art
[0002] The power modules in electric vehicles and their charging piles often need to store multiple consecutive data locally. Traditionally, to store multiple data of the same type continuously, an address area will be opened for the data of that type. The address area includes a data area and an index area. The data area is used to store data in a loop, and the index area is used to store the write index value of the data area in a loop, that is, the write position of the next data in the data area.
[0003] However, when the system unexpectedly loses power and then powers on again, the system cannot determine the power failure location and cannot achieve data power failure retrieval because there is more than one write index value in the index area. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a method, device and electronic device for data power-off preservation, so as to achieve data power-off preservation.
[0005] A first aspect of an embodiment of the present invention provides a power-off data retrieval method, the method being used to store data to be stored in an address area; the address area includes a data area and an index area, the data area is divided into a plurality of data storage units, each data storage unit cyclically stores the data to be stored, and the index area is divided into a plurality of index storage units, each index storage unit cyclically stores a write index value of the data area;
[0006] The method includes:
[0007] Get the data to be stored;
[0008] Checking in turn whether the write index value stored in each index storage unit is abnormal;
[0009] According to the detection result, the current write index value of the data area is determined from each write index value, and the data to be stored is stored in the data storage unit indicated by the current write index value.
[0010] Optionally, detecting whether a write index value is abnormal includes:
[0011] Determine whether the write index value is equal to zero, and calculate the absolute value of the difference between the write index value and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located;
[0012] If the write index value is equal to zero, it is determined whether the absolute value of the difference is equal to a first set value, and if the absolute value of the difference is not equal to the first set value, it is determined that the write index value is abnormal; wherein the first set value is the difference between the size of the data area and the size of the data storage unit;
[0013] If the write index value is not equal to zero, it is determined whether the absolute value of the difference is equal to a second set value. If the absolute value of the difference is not equal to the second set value, it is determined that the write index value is abnormal; wherein the second set value is the size of the data storage unit.
[0014] Optionally, according to the detection result, determining the current write index value of the data area from each write index value includes:
[0015] If a write index value is detected to be abnormal, the detection is terminated and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located is used as the current write index value of the data area;
[0016] If the detection result shows that all write index values are normal, the write index value stored in the last index storage unit in the index area is used as the current write index value of the data area.
[0017] Optionally, after storing the data to be stored in the data storage unit indicated by the current write index value, the method further includes:
[0018] Update the current write index value of the data area, and store the updated current write index value in the index area;
[0019] Among them, the storage position of the updated current write index value in the index area is the next index storage unit of the index storage unit where the current write index value is located; if the index storage unit where the current write index value is located is the last index storage unit in the index area, then the storage position of the updated current write index value in the index area is the first index storage unit in the index area.
[0020] Optionally, update the current write index value of the data area, including:
[0021] Update the current write index value of the data area according to Index'=Index+ByteLen;
[0022] Among them, Index' is the current write index value of the updated data area, Index is the current write index value of the data area before the update, ByteLen is the size of the data storage unit in the data area, if Index' is greater than or equal to the data area size, then Index' is set to zero.
[0023] Optionally, the size of the data storage unit in the data area is determined by the following formula:
[0024] ByteLen=L1 / C1
[0025] Where ByteLen is the size of the data storage unit, L1 is the length of the data to be stored, and C1 is the byte length of the data area.
[0026] Optionally, after acquiring the data to be stored, the method further includes:
[0027] According to the type of data to be stored, determining whether the data to be stored corresponds to the address area;
[0028] If the data to be stored corresponds to the address area, the data to be stored is stored in the address area; if the data to be stored does not correspond to the address area, the data to be stored is not stored.
[0029] A second aspect of an embodiment of the present invention provides a power-off data storage device, which is used to store data to be stored in an address area; the address area includes a data area and an index area, the data area is divided into a plurality of data storage units, each data storage unit cyclically stores the data to be stored, and the index area is divided into a plurality of index storage units, each index storage unit cyclically stores the write index value of the data area;
[0030] The device includes:
[0031] An acquisition module, used to acquire data to be stored;
[0032] A detection module, used to detect in turn whether the write index value stored in each index storage unit is abnormal;
[0033] The storage module is used to determine the current write index value of the data area from each write index value according to the detection result, and store the data to be stored in the data storage unit indicated by the current write index value.
[0034] A third aspect of an embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned data power-off preservation method when executing the computer program.
[0035] A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the power-off data preservation method as described above are implemented.
[0036] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0037] The power-off data preservation method provided by the embodiment of the present invention is to set a data area and an index area in the address area, the data area cyclically stores the data to be stored, and the index area cyclically stores the write index value of the data area; then based on the regularity between the write index values stored in the index area, when the system loses power and causes the storage process to be interrupted and then powered on again, by sequentially detecting whether each write index value stored in the index area is abnormal, according to the detection result, the current write index value of the data area is determined from each write index value, and the data to be stored is stored in the data storage unit indicated by the current write index value, so that the power-off data preservation can be achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0039] Figure 1 is an example diagram of an address area provided by an embodiment of the present invention;
[0040] Figure 2 It is a schematic diagram of the implementation flow of the power-off data storage method provided by an embodiment of the present invention;
[0041] Figure 3 is a schematic diagram of cyclic storage of write index values provided by an embodiment of the present invention;
[0042] Figure 4 This is a normal cycle storage flow chart of data provided by an embodiment of the present invention;
[0043] Figure 5 is a flow chart of data power-off storage provided by an embodiment of the present invention;
[0044] Figure 6 It is a structural schematic diagram of a power-off data storage device provided by an embodiment of the present invention;
[0045] Figure 7 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.
[0047] In order to illustrate the technical solution of the present invention, a specific embodiment is provided below for illustration.
[0048] When the power modules in electric vehicles and their charging piles operate under harsh conditions or abnormal situations occur, operational failures may occur. When network communication is abnormal, the failure cannot be transmitted to the server in real time. At this time, it is necessary to store the failure locally when the abnormality occurs. When the network communication is normal, the local data is uploaded to the server, which is conducive to finding problems and preventing accidents.
[0049] Therefore, an embodiment of the present invention provides a method for data power-off preservation, which is used to store data to be stored in an address area. The address area includes a data area and an index area, the data area is divided into a plurality of data storage units, each of which stores the data to be stored cyclically, and the index area is divided into a plurality of index storage units, each of which stores the write index value of the data area cyclically.
[0050] For example, see Figure 1 As shown, for the continuous storage of the same type of data, a corresponding address area is opened in the IIC memory, and the address area includes a data area and an index area. The data area stores the data content, and the index area stores the write index value of the data area, that is, the data write position. The data area and the index area can be continuous. For example, in an embodiment of the present invention, the data area is in front and the index area is in the back.
[0051] The data area is divided into multiple data storage units to cyclically store the data to be stored. Figure 1 In the data area, the size of DataLen is 28 bytes, and each byte is 8 bits. For a certain type of data with a length of 32 bits, each data needs to occupy 4 bytes, so the size of a data storage unit is ByteLen=4, and the data area can store n=7 data. When storing data, it starts from the first data storage unit. When the last data storage unit is also stored with data, the next data will be stored in the first data storage unit, overwriting the original data, and realizing the circular storage of data. The size of the data area DataLen can be set according to actual needs and is not limited here. Similarly, the index area also sets up multiple index storage units to cyclically store the write index value of the data area, and each index storage unit stores a write index value. The index area size IndexLen, the index storage unit size ByteLen, and the number m of write index values that can be stored in the index area can all be set according to actual needs and are not limited here.
[0052] When the system is powered off and then powered on again, since there is more than one index value stored in the index area, how to find the final write index value at the time of power failure from multiple write index values is the key to data preservation.
[0053] For the above questions, see Figure 2 As shown, the embodiment of the present invention provides a corresponding power-off storage method, which includes the following steps:
[0054] Step S101, obtaining data to be stored.
[0055] In the embodiment of the present invention, the data to be stored may be data such as fault conditions, operating time, working time, voltage and current, etc. The IIC memory allocates a corresponding address area for each type of data, and multiple consecutive data of the same type are stored in the same address area.
[0056] Step S102: sequentially detect whether the write index value stored in each index storage unit is abnormal.
[0057] In the embodiment of the present invention, the write index values stored in each index storage unit have a certain regularity. When a write index value does not meet the regularity, it is an abnormal write index value. The abnormal write index value is not truly abnormal, but can indicate the power-off moment.
[0058] Step S103: According to the detection result, determine the current write index value of the data area from each write index value, and store the data to be stored in the data storage unit indicated by the current write index value.
[0059] In an embodiment of the present invention, the power-off time can be determined based on the abnormal write index value, and then the current write index value of the data area, that is, the final write index value of the data area before power off, is determined. The data to be stored is written into the data area according to the final write index value, so that data can be retained after power off.
[0060] It can be seen that the data power-off preservation method provided by the embodiment of the present invention is to set a data area and an index area in the address area, the data area cyclically stores the data to be stored, and the index area cyclically stores the write index value of the data area; then based on the regularity between the write index values stored in the index area, when the system power is lost and the storage process is interrupted and powered on again, by successively detecting whether each write index value stored in the index area is abnormal, according to the detection result, the current write index value of the data area is determined from each write index value, and the data to be stored is stored in the data storage unit indicated by the current write index value, so that data power-off preservation can be achieved.
[0061] Optionally, in step S102, detecting whether a certain write index value is abnormal can be described in detail as follows:
[0062] Step S1021: determine whether the write index value is equal to zero, and calculate the absolute value of the difference between the write index value and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located.
[0063] Step S1022: If the write index value is zero, determine whether the absolute value of the difference is equal to a first set value; if the absolute value of the difference is not equal to the first set value, determine that the write index value is abnormal; wherein the first set value is the difference between the data area size and the data storage unit size.
[0064] Step S1023: if the write index value is not equal to zero, determine whether the absolute value of the difference is equal to a second set value; if the absolute value of the difference is not equal to the second set value, determine that the write index value is abnormal; wherein the second set value is the size of the data storage unit.
[0065] In the embodiments of the present invention, see Figure 3 As shown, the circular storage of the index area is explained. Assuming that the data area DataLen=28, the data storage unit size ByteLen=4, the index area size IndexLen=16, the index storage unit size ByteLen=4, and the number of write index values that can be stored in the index area m=4. Then the write index value stored in the index area in a circular manner will be in the range of 0-24, and will change in a circular manner with a step value of 4. In the first cycle, the first position of the write index value in the index area is 0, the second position is 4, the third position is 8, and the fourth position is 12. In the second cycle, the first position is first updated to 16, then the second position is updated to 20, and then the third position is updated to 24. Finally, the fourth position is updated to 0 because the data has completed a cycle in the data area and needs to be stored from the beginning. And so on for the third, fourth... cycles. It can be seen that under normal circumstances, the difference between the change in the write index value at a non-zero position and the previous write index value is the data storage unit size of 4, and the absolute value of the difference between the change in the write index value at 0 and the previous write index value is the difference between the data area size and the data storage unit size of 24. Each write index value is traversed in turn. When a write index value does not satisfy the above rules, it is an abnormal write index value.
[0066] Optionally, in step S102, according to the detection result, the current write index value of the data area is determined from each write index value, which can be described in detail as follows:
[0067] If a write index value is detected to be abnormal, the detection is terminated and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located is used as the current write index value of the data area;
[0068] If the detection result shows that all write index values are normal, the write index value stored in the last index storage unit in the index area is used as the current write index value of the data area.
[0069] In the embodiment of the present invention, based on step S102, when the system loses power, assuming that the first position of the second cycle is updated at this time, the write index value stored in the first position is 16, while the write index values of the second, third, and fourth positions are not updated, which are 4, 8, and 12 respectively. Traverse each write index value in turn, and when traversing to the second position, it is found that the difference between the write index value 4 stored therein and the previous write index value 16 is not equal to the data storage unit size 4, which does not conform to the rule under normal circumstances. Therefore, 4 can be determined as an abnormal write index value, and its previous write index value 16 is the final write index value updated before the power failure, that is, the continued storage position. The absolute value of the difference between the write index value at 0 and the previous write index value should be 24, otherwise 0 is the power failure position. In addition, if the index area just completes a cycle when the power is lost, the write index values in the index area will not be abnormal. At this time, the write index value stored in the last index storage unit of the index area is the final write index value updated before the power failure.
[0070] Optionally, after storing the data to be stored in the data storage unit indicated by the current write index value in step S103, the method further includes:
[0071] Update the current write index value of the data area, and store the updated current write index value in the index area;
[0072] Among them, the storage position of the updated current write index value in the index area is the next index storage unit of the index storage unit where the current write index value is located; if the index storage unit where the current write index value is located is the last index storage unit in the index area, then the storage position of the updated current write index value in the index area is the first index storage unit in the index area.
[0073] Optionally, update the current write index value of the data area, which can be detailed as:
[0074] Update the current write index value of the data area according to Index'=Index+ByteLen;
[0075] Among them, Index' is the current write index value of the updated data area, Index is the current write index value of the data area before the update, ByteLen is the size of the data storage unit in the data area, if Index' is greater than or equal to the data area size, then Index' is set to zero.
[0076] In the embodiment of the present invention, the write index value is used to indicate the starting storage position of the data to be stored in the data area. After each data is written according to the write index value, the write index value of the data area is updated according to the ending storage position of the data to realize the circular storage of the data in the data area. Similarly, the write index value is also circularly stored in the index area.
[0077] Optionally, the size of the data storage unit in the data area is determined by the following formula:
[0078] ByteLen=L1 / C1
[0079] Where ByteLen is the size of the data storage unit, L1 is the length of the data to be stored, and C1 is the byte length of the data area.
[0080] Since different types of data have different lengths, the sizes of data storage units for different types of data are also different. The size of the data storage unit can be calculated based on the data length and the number of bits in the data area.
[0081] Optionally, after acquiring the data to be stored, the method further includes:
[0082] According to the type of data to be stored, determining whether the data to be stored corresponds to the address area;
[0083] If the data to be stored corresponds to the address area, the data to be stored is stored in the address area; if the data to be stored does not correspond to the address area, the data to be stored is not stored.
[0084] In the data storage process, the data to be stored must first be placed in the buffer, and then the data is read from the buffer and stored in the corresponding address area according to the data type, that is, the same address area stores the same type of data. Therefore, before storing the data, first determine whether the data to be stored corresponds to the address area according to the type of the data to be stored. If not, the data will not be stored; or, the data will be stored in the address area corresponding to its type.
[0085] It should be noted that the power-off data preservation method proposed in the embodiment of the present invention can be used regardless of whether the system is powered off. However, in order to improve the data processing speed, it can be used only when the system is powered on again after power off. When the system is not powered off or power-off preservation is achieved, data can be stored cyclically through normal write index values. The specific process is as follows: Figure 4 As shown:
[0086] (1) Extract buffer data;
[0087] (2) writing data into the data area indicated by the index value;
[0088] (3) Determine whether the data is written successfully; if not, execute the external input operation instruction, and skip or rewrite the data area according to the operation instruction;
[0089] (4) Update the write index value;
[0090] (5) The updated write index value is stored in the index area at the location indicated by the index number index;
[0091] (6) The index number index in the index area automatically moves to the next or first index storage unit;
[0092] (7) Return to step (1) and extract the next data storage until there is no data in the buffer.
[0093] When the system is powered off and then powered on again, the power-off data preservation method described in this application can be used. The specific process is as follows: Figure 5 As shown: starting from the first index storage unit in the index area (i.e., reading the write index value IRead at the first address Iaddr of the index area), traverse the write index values, and when a certain write index value meets any one of the abnormal judgment conditions, return the previous write index value as the current write index value. If there is no abnormality in each write index value, the current write index value is defined as the write index value stored in the last index storage unit. After finding the power-off location according to the power-off preservation method for data described in the present application, it is also possible to continue to switch to the conventional loop storage process to further improve the data processing speed. The embodiment of the present invention finds the abnormal phenomenon point, determines the power-off time, and obtains the write index value at the power-off time. The method is simple and easy to understand, and does not require much storage space, so it is convenient for use when the index area is short.
[0094] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0095] See also Figure 6 As shown, an embodiment of the present invention further provides a data power-off surviving device, which is used to store data to be stored in an address area. The address area includes a data area and an index area, the data area is divided into a plurality of data storage units, each data storage unit cyclically stores the data to be stored, and the index area is divided into a plurality of index storage units, each index storage unit cyclically stores the write index value of the data area.
[0096] The device 60 comprises:
[0097] The acquisition module 61 is used to acquire data to be stored.
[0098] The detection module 62 is used to detect in turn whether the write index value stored in each index storage unit is abnormal.
[0099] The storage module 63 is used to determine the current write index value of the data area from each write index value according to the detection result, and store the data to be stored in the data storage unit indicated by the current write index value.
[0100] Optionally, the detection module 62 is specifically used for:
[0101] Determine whether the write index value is equal to zero, and calculate the absolute value of the difference between the write index value and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located;
[0102] If the write index value is equal to zero, it is determined whether the absolute value of the difference is equal to a first set value, and if the absolute value of the difference is not equal to the first set value, it is determined that the write index value is abnormal; wherein the first set value is the difference between the size of the data area and the size of the data storage unit;
[0103] If the write index value is not equal to zero, it is determined whether the absolute value of the difference is equal to a second set value. If the absolute value of the difference is not equal to the second set value, it is determined that the write index value is abnormal; wherein the second set value is the size of the data storage unit.
[0104] Optionally, the storage module 63 is specifically used for:
[0105] If a write index value is detected to be abnormal, the detection is terminated and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located is used as the current write index value of the data area;
[0106] If the detection result shows that all write index values are normal, the write index value stored in the last index storage unit in the index area is used as the current write index value of the data area.
[0107] Optionally, after storing the data to be stored in the data storage unit indicated by the current write index value, the storage module 63 is further configured to:
[0108] Update the current write index value of the data area, and store the updated current write index value in the index area;
[0109] Among them, the storage position of the updated current write index value in the index area is the next index storage unit of the index storage unit where the current write index value is located; if the index storage unit where the current write index value is located is the last index storage unit in the index area, then the storage position of the updated current write index value in the index area is the first index storage unit in the index area.
[0110] Optionally, the storage module 63 is further used for:
[0111] Update the current write index value of the data area according to Index'=Index+ByteLen;
[0112] Among them, Index' is the current write index value of the updated data area, Index is the current write index value of the data area before the update, ByteLen is the size of the data storage unit in the data area, if Index' is greater than or equal to the data area size, then Index' is set to zero.
[0113] Optionally, the storage module 63 is further used for:
[0114] The size of the data storage unit in the data area is determined according to the following formula:
[0115] ByteLen=L1 / C1
[0116] Where ByteLen is the size of the data storage unit, L1 is the length of the data to be stored, and C1 is the byte length of the data area.
[0117] Optionally, after acquiring the data to be stored, the acquisition module 61 is further used to:
[0118] According to the type of data to be stored, determining whether the data to be stored corresponds to the address area;
[0119] If the data to be stored corresponds to the address area, the data to be stored is stored in the address area; if the data to be stored does not correspond to the address area, the data to be stored is not stored.
[0120] Figure 7 FIG. 1 is a schematic diagram of an electronic device 70 provided by an embodiment of the present invention. Figure 7 As shown, the electronic device 70 of this embodiment includes: a processor 71, a memory 72, and a computer program 73 stored in the memory 72 and executable on the processor 71, such as a data power-off storage program. When the processor 71 executes the computer program 73, the steps in the above-mentioned data power-off storage method embodiments are implemented, such as Figure 1 Alternatively, when the processor 71 executes the computer program 73, the functions of each module in the above-mentioned device embodiments are realized, for example Figure 6 The functions of modules 61 to 63 are shown.
[0121] Exemplarily, the computer program 73 may be divided into one or more modules / units, one or more modules / units are stored in the memory 72, and executed by the processor 71 to complete the present invention. One or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 73 in the electronic device 70. For example, the computer program 73 may be divided into an acquisition module 61, a detection module 62, and a storage module 63 (modules in the virtual device), and the specific functions of each module are as follows:
[0122] The acquisition module 61 is used to acquire data to be stored.
[0123] The detection module 62 is used to detect in turn whether the write index value stored in each index storage unit is abnormal.
[0124] The storage module 63 is used to determine the current write index value of the data area from each write index value according to the detection result, and store the data to be stored in the data storage unit indicated by the current write index value.
[0125] The electronic device 70 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The electronic device 70 may include, but is not limited to, a processor 71 and a memory 72. Those skilled in the art will appreciate that Figure 7 It is only an example of the electronic device 70 and does not constitute a limitation of the electronic device 70. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 70 may also include input and output devices, network access devices, buses, etc.
[0126] The processor 71 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0127] The memory 72 may be an internal storage unit of the electronic device 70, such as a hard disk or memory of the electronic device 70. The memory 72 may also be an external storage device of the electronic device 70, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 70. Further, the memory 72 may also include both an internal storage unit of the electronic device 70 and an external storage device. The memory 72 is used to store computer programs and other programs and data required by the electronic device 70. The memory 72 may also be used to temporarily store data that has been output or is to be output.
[0128] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0129] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0130] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0131] In the embodiments provided by the present invention, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0132] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0133] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0134] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.
[0135] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.
Claims
1. A method for data power-off preservation, characterized in that: The method is used to store data to be stored in an address area; the address area includes a data area and an index area, the data area is divided into a plurality of data storage units, each data storage unit cyclically stores the data to be stored, and the index area is divided into a plurality of index storage units, each index storage unit cyclically stores the write index value of the data area; The method comprises: Get the data to be stored; Checking in turn whether the write index value stored in each index storage unit is abnormal; According to the detection result, determine the current write index value of the data area from each write index value, and store the data to be stored in the data storage unit indicated by the current write index value; Detecting whether a write index value is abnormal includes: Determine whether the write index value is equal to zero, and calculate the absolute value of the difference between the write index value and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located; If the write index value is equal to zero, it is determined whether the absolute value of the difference is equal to a first set value, and if the absolute value of the difference is not equal to the first set value, it is determined that the write index value is abnormal; wherein the first set value is the difference between the size of the data area and the size of the data storage unit; If the write index value is not equal to zero, determine whether the absolute value of the difference is equal to a second set value; if the absolute value of the difference is not equal to the second set value, determine that the write index value is abnormal; wherein the second set value is the size of the data storage unit.
2. The power-off data preservation method according to claim 1, characterized in that: Determining the current write index value of the data area from each write index value according to the detection result includes: If a write index value is detected to be abnormal, the detection is terminated and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located is used as the current write index value of the data area; If the detection result shows that all write index values are normal, the write index value stored in the last index storage unit in the index area is used as the current write index value of the data area.
3. The power-off data preservation method according to claim 1, characterized in that: After storing the data to be stored in the data storage unit indicated by the current write index value, the method further includes: Updating the current write index value of the data area, and storing the updated current write index value in the index area; Among them, the storage position of the updated current write index value in the index area is the next index storage unit of the index storage unit where the current write index value is located; if the index storage unit where the current write index value is located is the last index storage unit in the index area, then the storage position of the updated current write index value in the index area is the first index storage unit in the index area.
4. The power-off data preservation method according to claim 3, characterized in that: Updating the current write index value of the data area includes: Update the current write index value of the data area according to Index'=Index+ByteLen; Among them, Index' is the current write index value of the data area after update, Index is the current write index value of the data area before update, ByteLen is the size of the data storage unit in the data area, if Index' is greater than or equal to the data area size, then Index' is set to zero.
5. The power-off data preservation method according to any one of claims 1 to 4, characterized in that: The size of the data storage unit in the data area is determined by the following formula: ByteLen=L1 / C1 Wherein, ByteLen is the size of the data storage unit, L1 is the length of the data to be stored, and C1 is the byte length of the data area.
6. The power-off data preservation method according to any one of claims 1 to 4, characterized in that: After obtaining the data to be stored, it also includes: According to the type of the data to be stored, determining whether the data to be stored corresponds to the address area; If the data to be stored corresponds to the address area, the data to be stored is stored in the address area; if the data to be stored does not correspond to the address area, the data to be stored is not stored.
7. A data power-off storage device, characterized in that: The device is used to store data to be stored in an address area; the address area includes a data area and an index area, the data area is divided into a plurality of data storage units, each data storage unit cyclically stores the data to be stored, and the index area is divided into a plurality of index storage units, each index storage unit cyclically stores the write index value of the data area; The device comprises: An acquisition module, used to acquire data to be stored; A detection module, used to detect in turn whether the write index value stored in each index storage unit is abnormal; A storage module, used to determine the current write index value of the data area from each write index value according to the detection result, and store the data to be stored in the data storage unit indicated by the current write index value; Detecting whether a write index value is abnormal includes: Determine whether the write index value is equal to zero, and calculate the absolute value of the difference between the write index value and the write index value stored in the previous index storage unit of the index storage unit where the write index value is located; If the write index value is equal to zero, it is determined whether the absolute value of the difference is equal to a first set value, and if the absolute value of the difference is not equal to the first set value, it is determined that the write index value is abnormal; wherein the first set value is the difference between the size of the data area and the size of the data storage unit; If the write index value is not equal to zero, determine whether the absolute value of the difference is equal to a second set value; if the absolute value of the difference is not equal to the second set value, determine that the write index value is abnormal; wherein the second set value is the size of the data storage unit.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Method for power-down protection of storage system, storage controller and electronic equipment
CN106502928A