Data storage method, system, device and medium for realizing power-off retention

By dividing the A and B data areas in the hardware device memory and using the control header to record the validity information, the problem of data anomalies caused by power loss during writing is solved, automatic detection and data recovery are realized, and the dependence on the backup power supply is avoided, which improves the efficiency Reliability and cost-effectiveness of data storage.

CN114415948BActive Publication Date: 2024-10-25SUPCON TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111639818.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-29
Publication Date
2024-10-25
Estimated Expiration
2041-12-29

AI Technical Summary

Technical Problem

When the existing technology handles hardware memory data anomalies caused by power outage during writing, the detection conditions are harsh, automation cannot be realized, the operation is inconvenient, the data is unrecoverable, and there is no guarantee that the application can always obtain valid data.

Method used

By dividing the A and B data areas in the hardware device memory, and using the control header to record the validity information of the written data, ensure that the data is first written to the A area when writing, and then synchronized to the B area to determine the validity of the data in the two areas. , take the data in the valid data area and save it after power off.

Benefits of technology

It realizes automatic detection of data validity without manual intervention. Even if the power is lost during writing, it can ensure that the application obtains valid data, avoids the need to manually format the memory, and does not rely on backup power, improving the cost performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114415948B_ABST
    Figure CN114415948B_ABST
Patent Text Reader

Abstract

The present invention relates to a data storage method, system, device and medium for realizing power-off retention, wherein the method comprises: when writing data, first writing data into data area A through a control head, and then synchronizing the data into data area B; judging whether the written data of data areas A and B are valid through the control head: if the written data of data areas A and B are both valid, then the data of data area A is saved after power off; if only one of the written data of data areas A and B is valid, then the data of the valid data area is saved after power off. Applying the scheme of the present invention, when an application loads hardware memory data, it can automatically detect whether the data is valid without manual intervention; even if power off during writing causes abnormal memory data, valid data can be obtained; when power off causes abnormal memory data, there is no need to manually format the memory, and it can be automatically controlled by the application; the scheme of the present invention does not require backup power support, has a higher cost-effectiveness than the prior art, and has great promotion significance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data storage, and in particular to a data storage method, system, device and medium for realizing power-off retention. Background Art

[0002] When an application writes data to a hardware device, if there is a sudden power outage, it often causes memory data anomalies, such as missing or disordered data. After restarting the program, loading abnormal data will cause various problems, which may cause confusion in the running logic or even cause the program to freeze or even crash. Therefore, it is of great significance to ensure the correctness of hardware memory data when power is lost during writing.

[0003] There are two main methods for power-off retention: one is to add a log file to the application and use the log file to analyze whether the data has been written successfully when the power is off; the other is to add a backup power supply. When the main power supply module loses power, the backup power supply temporarily supplies power to ensure that the data writing operation can proceed. However, the existing technology has the following defects: the detection conditions are harsh, it cannot be automated, and the operation is inconvenient; the data cannot be restored, and it cannot be guaranteed that the application can always obtain valid data. Summary of the invention

[0004] 1. Technical issues to be resolved

[0005] In view of the above-mentioned shortcomings and deficiencies of the prior art, the present invention provides a data storage method, system, device and medium for realizing power-off retention, which solves the technical problems of the prior art that the detection conditions are harsh, automation cannot be realized, the operation is inconvenient; and the data is unrecoverable and it is impossible to ensure that the application program can always obtain valid data.

[0006] (II) Technical solution

[0007] In order to achieve the above object, the main technical solutions adopted by the present invention include:

[0008] In a first aspect, an embodiment of the present invention provides a data storage method for realizing power-off retention, comprising:

[0009] When writing data to the memory of the hardware device, the data is first written into the A data area through the control head, and then the data is synchronized to the B data area through the control head;

[0010] The control head is used to determine whether the written data in the A and B data areas are valid:

[0011] If the written data in data area A and B are both valid, the data in data area A will be saved after power failure;

[0012] If only one of the written data in data area A or B is valid, the data in the valid data area will be saved after power failure.

[0013] The hardware device memory includes a control head, an A data area and a B data area.

[0014] Optionally, the control header stores: the capacity of the A and B data areas, the actual valid data length, and a write flag.

[0015] Optionally, the capacities of the A data area and the B data area are consistent.

[0016] Optionally, when writing data to the hardware device memory, the data is first written to the A data area through the control header, including:

[0017] When writing data to the memory of the hardware device, firstly set the write flag of the A data area in the control header, and write the data into the A data area;

[0018] After the write operation is completed, the write flag of the A data area is reset, and the actual valid data length of the A data area is updated in the control header.

[0019] Optionally, synchronizing the data to the B data area through the control header includes:

[0020] First, the write flag of the B data area in the control header is set, and the data of the A data area is synchronously written to the B data area;

[0021] After the write operation is completed, the write flag of the B data area is reset and the effective data length of the B data area is updated.

[0022] Optionally, judging whether the written data in the A and B data areas are valid by the control head includes:

[0023] Reading a write flag of the A data area in the control header;

[0024] If the read result is false, it means that the last write operation of data area A is completed, and the data in data area A is judged to be valid;

[0025] If the read result is true, it means that the last write operation of the A data area was interrupted by power failure, then the data in the A data area is judged to be invalid, and the write flag of the B data area in the control header is read;

[0026] When the write flag reading result of the B data area is false, it is determined that the data in the B data area is valid.

[0027] Optionally, each time a write operation is completed, the write flag of the A data area / B data area in the control header is reset, and the actual effective length of the A data area / B data area is updated.

[0028] In a second aspect, an embodiment of the present invention provides a data storage system for realizing power-off retention, comprising:

[0029] A data writing module is used to write data to the memory of the hardware device by first writing the data to the A data area through the control head, and then synchronizing the data to the B data area through the control head;

[0030] The validity judgment module is used to judge whether the written data in the A and B data areas are valid through the control head:

[0031] The power-off access module is used to retrieve the data in the A data area and save it after power failure when both the written data in the A and B data areas are valid; when only one of the written data in the A and B data areas is valid, retrieve the data in the valid data area and save it after power failure;

[0032] The hardware device memory includes a control head, an A data area and a B data area.

[0033] In a third aspect, an embodiment of the present invention provides a data storage device that implements power-off retention, including:

[0034] at least one application database;

[0035] and a hardware device memory communicatively coupled to the at least one application database;

[0036] The application database stores instructions that can be executed by the at least one hardware device memory, and the instructions are executed by the at least one hardware device memory so that the at least one hardware device memory can execute the data storage method for realizing power-off retention as described above.

[0037] In a fourth aspect, an embodiment of the present invention provides a computer-readable medium having computer executable instructions stored thereon, wherein the executable instructions, when executed by a processor, implement a data storage method for achieving power-off retention as described above.

[0038] (III) Beneficial effects

[0039] The beneficial effects of the present invention are as follows: by applying the solution of the present invention, when an application loads hardware memory data, it can automatically detect whether the data is valid without manual intervention; even if a power outage during writing causes memory data abnormality, it can also ensure that the application can obtain valid data; when a power outage causes memory data abnormality, there is no need to manually format the memory, and it can be automatically managed by the application; the solution of the present invention does not require backup power support, thus eliminating the extra overhead brought by the backup power supply, has a higher cost-effectiveness than the prior art, and has greater promotion significance. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 A schematic flow chart of a method for storing data in a power-off state according to an embodiment of the present invention;

[0041] Figure 2 A schematic diagram of the composition of a hardware device memory for implementing a data storage method for power-off retention proposed by an embodiment of the present invention;

[0042] Figure 3 A schematic diagram of a specific flow chart of a part of step S1 of a method for storing data in a power-off state in an embodiment of the present invention;

[0043] Figure 4 Another specific flow chart of step S1 of a method for storing data in a power-off state according to an embodiment of the present invention;

[0044] Figure 5 A specific flow chart of step S2 of a method for storing data in a power-off state according to an embodiment of the present invention;

[0045] Figure 6 A schematic diagram of a data writing process of a data storage method for realizing power-off retention proposed by an embodiment of the present invention;

[0046] Figure 7 A schematic diagram of the composition of a data storage system for realizing power-off retention proposed by an embodiment of the present invention;

[0047] Figure 8 A schematic diagram of the structure of a computer system for a data storage device that implements power-off retention provided by an embodiment of the present invention.

[0048] [Description of Reference Numerals]

[0049] 100: data storage system for realizing power-off retention; 110: data writing module; 120: validity judgment module; 130: power-off access module;

[0050] 200: computer system; 201: CPU; 202: ROM; 203: RAM; 202: first bus; 205: I / O interface; 206: input part; 207: output part; 208: storage part; 209: communication part; 210: drive; 211: removable medium. DETAILED DESCRIPTION

[0051] In order to better explain the present invention and facilitate understanding, the present invention is described in detail below through specific implementation modes in conjunction with the accompanying drawings.

[0052] like Figure 1As shown, a data storage method for realizing power-off retention proposed in an embodiment of the present invention includes: first, when writing data to the memory of a hardware device, first write the data to the A data area through the control head, and then synchronize the data to the B data area through the control head; secondly, determine whether the written data in the A and B data areas are valid through the control head: if the written data in the A and B data areas are both valid, then the data in the A data area is saved after power is off; if only one of the written data in the A and B data areas is valid, then the data in the valid data area is saved after power is off; wherein, Figure 2 As shown, the memory of the hardware device is divided into three areas: the header, the A data area and the B data area. The control header records the capacity of the A and B data areas, the actual valid data length, the write flag and other information. A and B are two data storage areas of equal size, which are redundant in structure.

[0053] Therefore, the present invention achieves the following advantages: by applying the solution of the present invention, when an application loads hardware memory data, it can automatically detect whether the data is valid without manual intervention; even if a power outage during writing causes memory data abnormality, it can also ensure that the application can obtain valid data; when a power outage causes memory data abnormality, there is no need to manually format the memory, and it can be automatically managed by the application; the solution of the present invention does not require backup power support, thus eliminating the extra overhead brought by the backup power supply, and has a higher cost-effectiveness than the prior art, and has greater promotion significance.

[0054] In order to better understand the above technical solution, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a clearer and more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.

[0055] Specifically, the present invention provides a data storage method for realizing power-off retention, which comprises:

[0056] S1. When writing data to the memory of the hardware device, the data is first written to the A data area through the control head, and then the data is synchronized to the B data area through the control head.

[0057] like Figure 3 and Figure 4 As shown, step S1 includes:

[0058] S11. When writing data to the memory of the hardware device, first set the write flag of the A data area in the control header, and write the data into the A data area.

[0059] S12, after the write operation is completed, the write flag of the A data area is reset, and the actual valid data length of the A data area is updated in the control header.

[0060] S13, first set the write flag of the B data area in the control header, and synchronously write the data in the A data area to the B data area.

[0061] S14, after the write operation is completed, the write flag of the B data area is reset, and the effective data length of the B data area is updated.

[0062] S2. Determine whether the written data in data areas A and B is valid through the control head.

[0063] like Figure 5 As shown, step S2 includes:

[0064] S21, read the write flag of the A data area in the control header;

[0065] S22a, if the read result is false, it means that the last write operation of data area A is completed, and the data in data area A is determined to be valid;

[0066] S22b, if the read result is true, it means that the last write operation of the A data area was interrupted by power failure, then the data of the A data area is judged to be invalid, and the write flag of the B data area in the control header is read;

[0067] S23. When the write flag reading result of the B data area is false, it is determined that the data in the B data area is valid.

[0068] S3a. If the written data in data areas A and B are both valid, the data in data area A is saved after power failure.

[0069] S3b. If only one of the written data in the A and B data areas is valid, the data in the valid data area is saved after power failure.

[0070] like Figure 6 As shown, in a specific embodiment, when writing data, the application first sets the write flag of the A data area in the header, and resets the write flag after the data writing is completed, updates the actual valid data length of the A data area, and then sets the write flag of the B data area, resets the flag after the data writing is completed, and updates the valid data length of the B data area. When the application loads data, it first reads the write flag of the A data area in the control header. If it is false, it means that the last write operation is completed, the data in the A data area is valid, and the program uses the data in the A data area. If the write flag of the A data area is true, it means that the last write operation was interrupted by power failure, and the data in the A data area is invalid. Since the write value operation of the B data area is logically located after the write value of the A data area, the B data area has not yet been written, and its data is original data and is still valid. The application uses the data in the B data area, which can ensure that the application can always obtain valid data from the hardware device memory.

[0071] Preferably, each time a write operation is completed, the write flag of the A data area / B data area in the control header is reset, and the actual effective length of the A data area / B data area is updated. The application copies the data in the effective area to the invalid data area to achieve data synchronization, and at the same time resets the write flag in the control header, updates the effective length and other information, and prepares for the next write value.

[0072] The hardware device memory includes a control header, an A data area, and a B data area. The control header stores the capacity of the A and B data areas, the actual valid data length, and the write flag. The capacity of the A data area and the B data area are consistent, and not only the capacity is consistent, but also the data type, size, offset, structure, correlation, and continuity of the A data area and the B data area are consistent.

[0073] like Figure 7 As shown, the present invention provides a data storage system 100 for realizing power-off retention, comprising:

[0074] The data writing module 110 is used to write data to the memory of the hardware device by first writing the data to the A data area through the control head, and then synchronizing the data to the B data area through the control head.

[0075] The validity judgment module 120 is used to judge whether the written data in the A and B data areas are valid through the control head.

[0076] The power-off access module 130 is used to save the data in the A data area after power off when both the written data in the A and B data areas are valid; and to save the data in the valid data area after power off when only one of the written data in the A and B data areas is valid.

[0077] Since the system / device described in the above embodiments of the present invention is a system / device used to implement the method of the above embodiments of the present invention, a person skilled in the art can understand the specific structure and deformation of the system / device based on the method described in the above embodiments of the present invention, and thus will not be described in detail here. All systems / devices used in the method of the above embodiments of the present invention belong to the scope of protection of the present invention.

[0078] In addition, an embodiment of the present invention also provides a data storage device that implements power-off retention, including: at least one application database; and a hardware device memory that is communicatively connected to the at least one application database; wherein the application database stores instructions that can be executed by the at least one hardware device memory, and the instructions are executed by the at least one hardware device memory so that the at least one hardware device memory can execute a data storage method that implements power-off retention as described above.

[0079] Figure 8A schematic diagram of the structure of a computer system for implementing a data storage device that retains power during power failure provided by an embodiment of the present invention, see Figure 8 , which shows a schematic diagram of the structure of a computer system 200 suitable for implementing a data storage device for realizing power-off retention in one embodiment of the present application. Figure 8 The data storage device that implements power-off retention shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0080] like Figure 8 As shown, the computer system 200 includes a central processing unit (CPU) 201, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 202 or a program loaded from a storage part 208 into a random access memory (RAM) 203. In the RAM 203, various programs and data required for the operation of the computer system 200 are also stored. The CPU 201, the ROM 202, and the RAM 203 are connected to each other via a bus 204. An input / output interface (I / O interface) 205 is also connected to the bus 204.

[0081] The following components are connected to the I / O interface 205: an input section 206 including a keyboard, a mouse, etc.; an output section 207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 208 including a hard disk, etc.; and a communication section 209 including a network interface card such as a LAN card, a modem, etc. The communication section 209 performs communication processing via a network such as the Internet. A drive 210 is also connected to the I / O interface 205 as needed. A removable medium 211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 210 as needed, so that a computer program read therefrom is installed into the storage section 208 as needed.

[0082] In particular, according to an embodiment of the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 209, and / or installed from the removable medium 211. When the computer program is executed by the central processing unit (CPU) 201, the above-mentioned functions defined in the system of the present application are executed.

[0083] Furthermore, the present invention provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes the following method steps:

[0084] S1. When writing data to the memory of the hardware device, the data is first written to the A data area through the control head, and then the data is synchronized to the B data area through the control head.

[0085] S2. Determine whether the written data in data areas A and B is valid through the control head.

[0086] S3. If the written data in data areas A and B are both valid, the data in data area A is saved after power failure.

[0087] S4. If only one of the written data in the A and B data areas is valid, the data in the valid data area is saved after power failure.

[0088] In a specific industrial application scenario, the PID algorithm is used in the controller to adjust the field equipment. The PID algorithm needs to make appropriate adjustments to the three input values ​​of P, I, and D according to the feedback value of the field data. Repeated calculations and accumulation will eventually stabilize the equipment to achieve the control effect. If the field equipment suddenly loses power, the intermediate process data of the PID algorithm will be discarded, and the PID algorithm will restart the calculation, slowly accumulating the feedback value of the field equipment to re-check the PID data. It will stabilize again after a sufficient number of calculations. Therefore, after a power-off retention data storage method is applied to the field, if the equipment suddenly loses power, the intermediate data can still be retained, and the controller can quickly stabilize the field equipment.

[0089] In summary, the present invention proposes a data storage method, system, device and medium for realizing power-off retention, which pre-divides the memory of the hardware device into three storage areas, namely, a control header, A and B data areas of the same size, and the control header contains information such as the current data size and validity of the A and B data areas. When an application writes certain data, it is assisted by the control header, and the information of the control header is first modified, and then the data is written into the A data area, and then the control header is modified to synchronize the data to the B data area. The application can use the control header to determine whether the data in the A and B data areas are legal: if both the A and B data areas are valid, the data in the A data area is taken; if only one of the data in the A and B data areas is valid, the data in the valid data area is taken to prevent abnormal timing data files caused by power failure.

[0090] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0091] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions.

[0092] It should be noted that in the claims, any reference numerals placed between brackets shall not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention may be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In the claims enumerating several means, several of these means may be embodied by the same hardware. The use of the words first, second, third, etc., is for convenience of expression only and does not indicate any order. These words may be understood as part of the component name.

[0093] In addition, it should be noted that, in the description of this specification, the description of the terms "one embodiment", "some embodiments", "embodiment", "example", "specific example" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.

[0094] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments after knowing the basic creative concept. Therefore, the claims should be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present invention.

[0095] Obviously, those skilled in the art can make various modifications and variations to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention should also include these modifications and variations.

Claims

1. A method for storing data in a power-off state, characterized in that: include: When writing data to the memory of the hardware device, the data is first written into the A data area through the control head, and then the data is synchronized to the B data area through the control head; The control head is used to determine whether the written data in the A and B data areas are valid: If the written data in data area A and B are both valid, the data in data area A will be saved after power failure; If only one of the written data in data area A or B is valid, the data in the valid data area will be saved after power failure. in, Judging whether the written data in the A and B data areas are valid by the control head includes: Reading a write flag of the A data area in the control header; If the read result is false, it means that the last write operation of data area A is completed, and the data in data area A is judged to be valid; If the read result is true, it means that the last write operation of the A data area was interrupted by power failure, then the data in the A data area is judged to be invalid, and the write flag of the B data area in the control header is read; When the write flag reading result of the B data area is false, it is judged that the data in the B data area is valid; The hardware device memory includes a control head, an A data area and a B data area; The control header stores: the capacity of the A and B data areas, the actual valid data length and the write flag; The capacities of the A data area and the B data area are consistent.

2. A method for storing data in a power-off state as claimed in claim 1, characterized in that: When writing data to the hardware device memory, the data is first written to the A data area through the control header, including: When writing data to the memory of the hardware device, firstly set the write flag of the A data area in the control header, and write the data into the A data area; After the write operation is completed, the write flag of the A data area is reset, and the actual valid data length of the A data area is updated in the control header.

3. A method for storing data in a power-off state as claimed in claim 1, characterized in that: Then synchronizing the data to the B data area through the control header includes: First, the write flag of the B data area in the control header is set, and the data of the A data area is synchronously written to the B data area; After the write operation is completed, the write flag of the B data area is reset and the effective data length of the B data area is updated.

4. A method for storing data in a power-off state according to any one of claims 1 to 3, characterized in that: Each time a write operation is completed, the write flag of the A data area / B data area in the control header is reset, and the actual effective length of the A data area / B data area is updated.

5. A data storage system that realizes power-off retention, characterized in that: include: A data writing module is used to write data to the memory of the hardware device by first writing the data to the A data area through the control head, and then synchronizing the data to the B data area through the control head; The validity judgment module is used to judge whether the written data in the A and B data areas are valid through the control head: The power-off access module is used to fetch the data in the A data area and save it after power failure when both the written data in the A and B data areas are valid; and fetch the data in the valid data area and save it after power failure when only one of the written data in the A and B data areas is valid; in, Judging whether the written data in the A and B data areas are valid by the control head includes: Reading a write flag of the A data area in the control header; If the read result is false, it means that the last write operation of data area A is completed, and the data in data area A is judged to be valid; If the read result is true, it means that the last write operation of the A data area was interrupted by power failure, then the data in the A data area is judged to be invalid, and the write flag of the B data area in the control header is read; When the write flag reading result of the B data area is false, it is judged that the data in the B data area is valid; The hardware device memory includes a control head, an A data area and a B data area; The control header stores: the capacity of the A and B data areas, the actual valid data length and the write flag; The capacities of the A data area and the B data area are consistent.

6. A data storage device that can maintain power failure, characterized in that: include: at least one application database; and a hardware device memory communicatively coupled to the at least one application database; Among them, the application database stores instructions that can be executed by at least one hardware device memory, and the instructions are executed by the at least one hardware device memory so that the at least one hardware device memory can execute a data storage method for realizing power-off retention as described in any one of claims 1-4.

7. A computer-readable medium having computer-executable instructions stored thereon, characterized in that: When the executable instructions are executed by the processor, a method for storing data in a power-off state as described in any one of claims 1 to 4 can be implemented.