A production system configuration file acquisition method and medium
Patent Information
- Application Number
- CN202210663097.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-13
- Publication Date
- 2026-09-25
- Estimated Expiration
- 2042-06-13
AI Technical Summary
频繁重复写入容易引起磁盘坏道,从而导致配置文件损坏
[0030]本发明采用将待写入配置文件按配置文件组成顺序拆分成多个固定大小的第一子文件,在写入配置文件时,先按照固定块大小将待写入配置文件的每个第一子文件与原配置文件中对应的第二子文件进行比较,将内容有变化的第一子文件以创建文件的方式写入至磁盘的随机存储区域,并创建第一临时索引文件对内容有变化的所述第一子文件和内容无变化的所述第二子文件进行索引,然后将该第一临时索引文件转换为正式索引文件,在读取配置文件时,更新后的索引文件读取所有子文件按配置文件组成顺序进行拼接形成完整的配置文件作为该生产系统新的配置文件。通过上述步骤对于一些体积较大的配置文件进行少量修改时,不用再覆写其整个配置文件,只需新增少量的内容有变化的新的子文件,删除少量旧的子文件即可。更新后的索引文件和新增的子文件都是新创建的文件,写入位置是随机的,因此不会发生在固定位置重复写入而产生磁盘坏道,大幅减少因频繁更新配置文件引发的磁盘损坏而导致配置文件损坏的概率。
Smart Images

Figure CN117270983B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of information processing technology, and more specifically, relates to a method and medium for obtaining configuration files of a production system. Background Technology
[0002] When configuration files are updated frequently, they are written to the disk repeatedly, often overwriting existing files in the same locations. This frequent rewriting can cause bad sectors on the disk, leading to configuration file corruption.
[0003] In production environments, especially industrial settings, a power outage during the writing of a configuration file may cause the configuration file to become corrupted. This corruption can lead to program crashes or logical instability, which in turn can result in production safety accidents or losses. Therefore, technical means are needed to avoid this problem. Summary of the Invention
[0004] This invention addresses the aforementioned shortcomings of existing technologies by proposing a method and medium for obtaining production system configuration files. When making minor modifications to large configuration files, it eliminates the need to overwrite the entire file; instead, it suffices to add a few new sub-files with changed content and delete a few old sub-files. Both the updated index file and the newly added sub-files are newly created files, and their write locations are randomized. This avoids repeatedly writing configuration files to fixed locations, preventing disk bad sectors and significantly reducing the probability of configuration file corruption due to disk damage caused by frequent updates.
[0005] To achieve the above objectives, the technical solution of the present invention is as follows:
[0006] A method for obtaining a production system configuration file includes:
[0007] Step S1: Split the configuration file to be written into multiple fixed-size first sub-files in the order of its composition;
[0008] Step S2: Locate the original index file of the original configuration file of the production system, and obtain multiple second sub-files that make up the original configuration file;
[0009] Step S3: Compare each first sub-file with the corresponding second sub-file, and write the first sub-file whose content has changed to the random storage area of the disk;
[0010] Step S4: Create a first temporary index file and index the first sub-file whose content has changed and the second sub-file whose content has not changed;
[0011] Step S5: Convert the first temporary index file into an index file, read the corresponding second sub-file in the original configuration file and the first sub-file in the random storage area according to the index file, and assemble them into a complete configuration file according to the configuration file composition order as the new configuration file of the production system.
[0012] Preferably, step S4 includes:
[0013] Step S41: Create a first temporary index file, the file name of the first temporary index file is the file name of the original index file with a suffix added;
[0014] Step S42: The filenames of the first sub-file whose content has changed and the filenames of the second sub-file whose content has not changed are sequentially stored into the first temporary index file to form an index.
[0015] Preferably, in step S5, converting the first temporary index file into an index file includes:
[0016] Step S51: Rename the original index file to a second temporary index file;
[0017] Step S52: Rename the first temporary index file using the filename of the original index file;
[0018] Step S5 further includes: after converting the first temporary index file into an index file, deleting the second temporary index file and the second sub-file whose content has changed.
[0019] Preferably, before reading the corresponding second sub-file in the original configuration file and the first sub-file in the random storage area according to the index file, the method further includes:
[0020] Step a1: Determine if the second temporary index file exists. If it does, restore the second temporary index file to the index file. Otherwise, proceed to step a2.
[0021] Step a2: Determine whether the first temporary index file exists. If it does, clear the first temporary index file; otherwise, proceed to step a3.
[0022] Step a3: Determine whether there are any first sub-files whose content has changed and which have not been indexed in the index file. If so, clear the corresponding first sub-file.
[0023] Preferably, in step S2, a sub-file list is obtained based on the original index file. The sub-file list maps to multiple second sub-files. The sub-file list is an array formed by combining the filenames of multiple second sub-files. The array can be any one of an integer array, a long integer array, or a string array.
[0024] Preferably, when the array is in the form of an integer array or a long integer array, the first sub-file whose content has changed is written into the random storage area. For each first sub-file whose content has changed, the file name is incremented from the maximum value obtained by traversing the file names in the sub-file list, and the file name of the first sub-file is updated in the sub-file list.
[0025] Preferably, when the array is a string array, the filenames of the first sub-files whose content has changed are named using UUID strings.
[0026] Preferably, the space used to store each fixed-size first sub-file is greater than or equal to the size of a disk sector, and is 2 to the power of N bytes.
[0027] Preferably, in step S3, the file contents of the first sub-file and the corresponding second sub-file are compared using binary comparison.
[0028] The present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for obtaining production system configuration files.
[0029] The beneficial effects of the technical solution of the present invention are as follows:
[0030] This invention employs a method of splitting the configuration file to be written into multiple fixed-size first sub-files according to the configuration file's composition order. When writing the configuration file, each first sub-file is compared with its corresponding second sub-file in the original configuration file according to a fixed block size. First sub-files with changed content are written to the random storage area of the disk as newly created files. A first temporary index file is created to index the changed first sub-files and the unchanged second sub-files. This first temporary index file is then converted into a formal index file. When reading the configuration file, the updated index file reads all sub-files and assembles them according to the configuration file's composition order to form a complete configuration file, which serves as the new configuration file for the production system. Through these steps, when making minor modifications to some large configuration files, it is not necessary to overwrite the entire configuration file; only a few new sub-files with changed content need to be added, and a few old sub-files need to be deleted. Since the updated index file and the newly added sub-files are newly created files with random write locations, repeated writing to fixed locations will not occur, thus avoiding disk bad sectors and significantly reducing the probability of configuration file corruption caused by disk damage due to frequent configuration file updates.
[0031] Furthermore, by first writing the newly added first sub-file, then writing it to the first temporary index file, updating the first temporary index file to the index file, and finally deleting the original index file and the useless second sub-file in the original configuration file, even if an abnormal situation such as a power outage occurs when writing the first temporary index file, the original index file can be restored to the index file, thereby restoring the configuration file to its previous intact state and ensuring that the production system can obtain the configuration file normally. Attached Figure Description
[0032] The above and other objects, features and advantages of the present invention will become more apparent from the more detailed description of exemplary embodiments of the invention in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the invention.
[0033] Figure 1 A flowchart illustrating a method for obtaining configuration files in a production system provided by the present invention;
[0034] Figure 2 A schematic diagram illustrating the composition of a configuration file for a production system configuration file acquisition method provided by the present invention;
[0035] Figure 3 A comparison diagram of the status of a production system configuration file acquisition method before and after update, provided by the present invention;
[0036] Figure 4A flowchart illustrating the process of writing a configuration file in a method for obtaining a configuration file in a production system, as provided in an embodiment of the present invention;
[0037] Figure 5 This is a flowchart illustrating the process of reading a configuration file in a production system configuration file acquisition method provided in an embodiment of the present invention. Detailed Implementation
[0038] Preferred embodiments of the invention will now be described in more detail. While preferred embodiments of the invention are described below, it should be understood that the invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that the invention will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
[0039] Configuration files are widely used in software systems, especially in industrial settings. They store critical information about system operation, and if they are damaged, the data is irrecoverable. This damage can also affect the operation of industrial production systems, thereby impacting normal production and causing economic losses or safety accidents.
[0040] One reason for configuration file corruption is frequent updates by applications. Generally, when the operating system's file system overwrites a configuration file, it does so at the original disk location. Frequent overwriting can cause bad sectors and other problems in the corresponding disk locations, thus corrupting the configuration file itself. (See reference...) Figure 1 As shown, the present invention provides a method for obtaining a production system configuration file, including:
[0041] Step S1: Split the configuration file to be written into multiple fixed-size first sub-files in the order of its composition;
[0042] Step S2: Locate the original index file of the original configuration file of the production system and obtain the multiple second sub-files that make up the original configuration file;
[0043] Step S3: Compare each first sub-file with its corresponding second sub-file, and write the first sub-file whose content has changed to the random storage area of the disk;
[0044] Step S4: Create a first temporary index file and index the first sub-file whose content has changed and the second sub-file whose content has not changed;
[0045] Step S5: Convert the first temporary index file into an index file, read the corresponding second sub-file in the original configuration file and the first sub-file in the random storage area according to the index file, and assemble them into a complete configuration file according to the configuration file composition order as the new configuration file for the production system.
[0046] Specifically, such as Figure 2 As shown, the configuration file consists of an index file and multiple corresponding sub-files (e.g., sub-file 0, sub-file 1, sub-file 2, ...). The index file stores the mapping relationship between the index file and the multiple sub-files, recording which sub-files make up the configuration file. The configuration file to be written is split into multiple fixed-size first sub-files according to the configuration file's composition order. When writing the configuration file, each first sub-file to be written is first compared with its corresponding second sub-file in the original configuration file according to a fixed block size. First sub-files with changed content are written to the random access area of the disk as newly created files, and a first temporary index file is created to index the changed first sub-files and the unchanged second sub-files. This first temporary index file is then converted into a formal index file. When reading the configuration file, the updated index file reads all sub-files and concatenates them according to the configuration file's composition order to form a complete configuration file, which becomes the new configuration file for the production system. Figure 3 As shown, the index file xxx.index of the configuration file before the update contained three subfiles: subfile 0, subfile 1, and subfile 2. These subfiles were also stored in the same folder. When the application modified the configuration file, the contents of subfiles 0 and 1 remained unchanged, while the contents of subfile 2 changed. Therefore, a new subfile 3 was created, the old subfile 2 was deleted, and the index file was updated with subfiles 0, 1, and 3. By following these steps, when making minor modifications to large configuration files, it's not necessary to overwrite the entire configuration file; only a few new subfiles with changed content need to be added, and a few old subfiles need to be deleted. The updated index file and the newly added subfiles are all newly created files, and the write location is random. Therefore, repeated writing to fixed locations will not cause disk bad sectors, significantly reducing the probability of configuration file corruption due to disk damage caused by frequent configuration file updates.
[0047] Optionally, step S4 includes:
[0048] Step S41: Create a first temporary index file. The filename of the first temporary index file is the original index file name with a suffix added.
[0049] Step S42: Store the filenames of the first sub-file whose content has changed and the filenames of the second sub-file whose content has not changed into the first temporary index file to form an index.
[0050] Specifically, if the original index file is named xxx.index, then the first temporary index file is named xxx.index.new. Then, the filenames of the second sub-file with unchanged content and the newly created first sub-file with changed content are used as indexes and stored sequentially into the first temporary index file xxx.index.new. This avoids indexing operations based on the original index file xxx.index and can prevent the original index file from being lost in the event of a power outage.
[0051] Optionally, in step S5, converting the first temporary index file into an index file includes:
[0052] Step S51: Rename the original index file to a second temporary index file;
[0053] Step S52: Rename the first temporary index file using the original index file's filename;
[0054] Step S5 also includes: after converting the first temporary index file into an index file, deleting the second temporary index file and the second sub-file whose content has changed.
[0055] Specifically, the original index file is renamed to the second temporary index file xxx.index.old, then the first temporary index file xxx.index.new is renamed to the new index file xxx.index. Next, the second temporary index file xxx.index.old is deleted, along with the second sub-file in the original configuration file that is no longer used in the configuration file to be written. The approach of first updating the first temporary index file xxx.index.new to the new index file xxx.index, and then finally deleting the second temporary index file xxx.index.old and the second sub-file whose content has changed, is to prevent the old index file from failing to find the corresponding sub-file and thus being unable to restore the configuration file when the new index file has not yet been written due to a power outage.
[0056] Optionally, before reading the corresponding second sub-file in the original configuration file and the first sub-file in the random storage area based on the index file, the following steps are also included:
[0057] Step a1: Determine if a second temporary index file exists. If it does, restore the second temporary index file to the index file. Otherwise, proceed to step a2.
[0058] Step a2: Determine if a first temporary index file exists. If it does, clear the first temporary index file; otherwise, proceed to step a3.
[0059] Step a3: Determine if there is a first sub-file in the index file whose content has changed and has not been indexed. If so, clear the corresponding first sub-file.
[0060] Specifically, when reading the configuration file, the system first checks if a second temporary index file, xxx.index.old, exists. If it does, it means that a power outage occurred when the first temporary index file, xxx.index.new, was renamed to the new index file, xxx.index. In this case, the second temporary index file, xxx.index.old, is restored to the original index file, xxx.index. Next, it checks if a first temporary index file, xxx.index.new, exists. If it does, it means that a power outage occurred when the first temporary index file, xxx.index.new, was written to. In this case, the first temporary index file is cleared. Then, it checks if any first sub-files with changed content are not present in the configuration file's index. If so, it means that a power outage occurred during the last index update, and the newly created sub-files have not yet been written to the new index file. Therefore, these redundant sub-files generated by the power outage need to be cleared. Finally, the system reads the index file, obtains the list of sub-files, reads the sub-files sequentially, assembles them into a complete configuration file, and returns the reading result to the application layer. Therefore, when reading the configuration file, the above steps are used to first clean up file anomalies caused by power failure, and then all sub-files are read according to the index file and concatenated to form a complete configuration file, thereby releasing disk storage space and preventing newly created sub-files from becoming junk files and occupying disk space.
[0061] Optionally, in step S2, a sub-file list is obtained based on the original index file. The sub-file list maps to multiple second sub-files. The sub-file list is an array formed by combining the filenames of multiple second sub-files. The array can be any one of an integer array, a long integer array, or a string array.
[0062] Optionally, when the array is an integer array or a long integer array, the first sub-file whose content has changed is written to the random storage area. For each first sub-file whose content has changed, the file name is incremented by the maximum value obtained by traversing the file name in the sub-file list, and the file name of the first sub-file is updated to the sub-file list.
[0063] Optionally, when the array is a string array, the filenames of the first sub-files whose content has changed are named using UUID strings.
[0064] Specifically, the subfile list is a 64-bit long integer array. Each element in the array represents the filename of the corresponding subfile. The array is traversed to obtain the maximum value of its elements. For example, if the maximum value is 2200000, this maximum value is incremented by 1 to become the filename of the first subfile, which is 2200001. This filename 2200001 is then appended to the end of the subfile list. Subsequent newly created first subfiles are named by incrementing the maximum filename by 1, resulting in 2200002, 2200003, and so on, ensuring that the filename of each created first subfile is unique. In other embodiments, a 32-bit integer array or a string array in UUID form can also be used to represent the set of subfile filenames.
[0065] Optionally, the space used to store each fixed-size first sub-file is greater than or equal to the size of a disk sector, and is 2 to the power of N bytes.
[0066] Optionally, in step S3, the contents of the first sub-file and the corresponding second sub-file are compared using binary comparison.
[0067] Specifically, the configuration file to be written needs to be divided into multiple first sub-files of a fixed size. Generally, the size of the sub-file should be at least greater than or equal to the size of a disk sector, for example, set to 4KB, to facilitate comparison. The new first sub-files are traversed sequentially using binary data. Each first sub-file is compared with the corresponding second sub-file of the original configuration file. If the binary data is the same, the first sub-file is considered unchanged, and the original second sub-file and its filename are used. If no matching sub-file is found in any of the original second sub-files, it is considered a new first sub-file. This process continues until all first sub-files have been compared.
[0068] Furthermore, to speed up the comparison process, checksums for all first and second sub-files can be calculated using algorithms such as SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512. These checksums can then be compared instead of binary comparisons, thus improving the efficiency of file content comparison.
[0069] Example 1
[0070] Reference Figure 1-5 As shown, this embodiment provides a method for obtaining a production system configuration file, including:
[0071] Step S1: Split the configuration file to be written into multiple fixed-size first sub-files in the order of its composition;
[0072] Step S2: Locate the original index file of the original configuration file of the production system and obtain the multiple second sub-files that make up the original configuration file;
[0073] Step S3: Compare each first sub-file with its corresponding second sub-file, and write the first sub-file whose content has changed to the random storage area of the disk;
[0074] Step S4: Create a first temporary index file and index the first sub-file whose content has changed and the second sub-file whose content has not changed;
[0075] Step S5: Convert the first temporary index file into an index file, read the corresponding second sub-file in the original configuration file and the first sub-file in the random storage area according to the index file, and assemble them into a complete configuration file according to the configuration file composition order as the new configuration file for the production system.
[0076] In this embodiment, step S4 includes:
[0077] Step S41: Create a first temporary index file. The filename of the first temporary index file is the original index file name with a suffix added.
[0078] Step S42: Store the filenames of the first sub-file whose content has changed and the filenames of the second sub-file whose content has not changed into the first temporary index file to form an index.
[0079] In this embodiment, step S5, converting the first temporary index file into an index file, includes:
[0080] Step S51: Rename the original index file to a second temporary index file;
[0081] Step S52: Rename the first temporary index file using the original index file's filename;
[0082] Step S5 also includes: after converting the first temporary index file into an index file, deleting the second temporary index file and the second sub-file whose content has changed.
[0083] In this embodiment, before reading the corresponding second sub-file in the original configuration file and the first sub-file in the random storage area according to the index file, the following steps are also included:
[0084] Step a1: Determine if a second temporary index file exists. If it does, restore the second temporary index file to the index file. Otherwise, proceed to step a2.
[0085] Step a2: Determine if a first temporary index file exists. If it does, clear the first temporary index file; otherwise, proceed to step a3.
[0086] Step a3: Determine if there is a first sub-file in the index file whose content has changed and has not been indexed. If so, clear the corresponding first sub-file.
[0087] In this embodiment, in step S2, a sub-file list is obtained based on the original index file. The sub-file list maps to multiple second sub-files. The sub-file list is an array formed by combining the filenames of multiple second sub-files. The array can be any one of an integer array, a long integer array, or a string array.
[0088] In this embodiment, when the array is in the form of an integer array or a long integer array, the first sub-file whose content has changed is written to the random storage area. For each first sub-file whose content has changed, the maximum value obtained by traversing the filenames in the sub-file list is incremented as the starting point and used as the filename of the first sub-file. The filename of the first sub-file is then updated in the sub-file list.
[0089] In this embodiment, when the array is a string array, the filename of the first sub-file whose content has changed is named using the UUID string format.
[0090] In this embodiment, the space for storing each fixed-size first sub-file is greater than or equal to the size of a disk sector, and is 2 to the power of N bytes.
[0091] In this embodiment, in step S3, the file contents of the first sub-file and the corresponding second sub-file are compared using binary comparison.
[0092] Figure 4 A flowchart illustrating the process of writing a configuration file in a method for obtaining a configuration file in a production system, as provided in an embodiment of the present invention; Figure 5 This is a flowchart illustrating the process of reading a configuration file in a production system configuration file acquisition method provided in an embodiment of the present invention.
[0093] Example 2
[0094] The present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described production system configuration file acquisition method. According to the computer-readable storage medium disclosed in this embodiment, non-transitory computer-readable instructions are stored thereon. When these non-transitory computer-readable instructions are executed by a processor, all or part of the steps of the methods described in the foregoing embodiments are performed.
[0095] The aforementioned computer-readable storage media include, but are not limited to: optical storage media (e.g., CD-ROM and DVD), magneto-optical storage media (e.g., MO), magnetic storage media (e.g., magnetic tape or portable hard drive), media with built-in rewritable non-volatile memory (e.g., memory card), and media with built-in ROM (e.g., ROM cartridge).
[0096] In summary, this invention allows for minor modifications to large configuration files without overwriting the entire configuration file. Instead, it suffices to add a few new sub-files with changed content and delete a few old sub-files. Since the updated index file and the newly added sub-files are newly created files with random write locations, it avoids repeated writing to fixed locations that could cause disk bad sectors, significantly reducing the probability of configuration file corruption due to disk damage caused by frequent updates.
[0097] The various embodiments of the present invention have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments.
Claims
1. A method for obtaining configuration files in a production system, characterized in that, include: Step S1: Split the configuration file to be written into multiple fixed-size first sub-files in the order of its composition; Step S2: Locate the original index file of the original configuration file of the production system, and obtain multiple second sub-files that make up the original configuration file; Step S3: Compare each first sub-file with the corresponding second sub-file, and write the first sub-file whose content has changed to the random storage area of the disk; Step S4: Create a first temporary index file and index the first sub-file whose content has changed and the second sub-file whose content has not changed; Step S5: Convert the first temporary index file into an index file, read the corresponding second sub-file in the original configuration file and the first sub-file in the random storage area according to the index file, and assemble them into a complete configuration file according to the configuration file composition order as the new configuration file of the production system.
2. The method for obtaining production system configuration files according to claim 1, characterized in that, Step S4 includes: Step S41: Create a first temporary index file, the file name of the first temporary index file is the file name of the original index file with a suffix added; Step S42: The filenames of the first sub-file whose content has changed and the filenames of the second sub-file whose content has not changed are sequentially stored into the first temporary index file to form an index.
3. The method for obtaining production system configuration files according to claim 1, characterized in that, In step S5, converting the first temporary index file into an index file includes: Step S51: Rename the original index file to a second temporary index file; Step S52: Rename the first temporary index file using the filename of the original index file; Step S5 further includes: after converting the first temporary index file into an index file, deleting the second temporary index file and the second sub-file whose content has changed.
4. The method for obtaining production system configuration files according to claim 3, characterized in that, Before reading the corresponding second sub-file in the original configuration file and the first sub-file in the random storage area according to the index file, the following steps are also included: Step a1: Determine if the second temporary index file exists. If it does, restore the second temporary index file to the index file. Otherwise, proceed to step a2. Step a2: Determine whether the first temporary index file exists. If it does, clear the first temporary index file; otherwise, proceed to step a3. Step a3: Determine whether there are any first sub-files whose content has changed and which have not been indexed in the index file. If so, clear the corresponding first sub-file.
5. The method for obtaining production system configuration files according to claim 1, characterized in that, In step S2, a sub-file list is obtained based on the original index file. The sub-file list maps to multiple second sub-files. The sub-file list is an array formed by combining the filenames of multiple second sub-files. The array can be any one of an integer array, a long integer array, or a string array.
6. The method for obtaining production system configuration files according to claim 5, characterized in that, When the array is in the form of an integer array or a long integer array, the first sub-file whose content has changed is written into the random storage area. For each first sub-file whose content has changed, the file name is incremented from the maximum value obtained by traversing the file names in the sub-file list, and the file name of the first sub-file is updated to the sub-file list.
7. The method for obtaining production system configuration files according to claim 5, characterized in that, When the array is a string array, the filenames of the first sub-files whose content has changed are named using UUID strings.
8. The method for obtaining production system configuration files according to claim 1, characterized in that, The space used to store each fixed-size first sub-file is greater than or equal to the size of a disk sector, and is 2 to the power of N bytes.
9. The method for obtaining production system configuration files according to claim 1, characterized in that, In step S3, the file contents of the first sub-file and the corresponding second sub-file are compared using binary comparison.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the production system configuration file acquisition method according to any one of claims 1-9.
Citation Information
Patent Citations
Index-based power frequency recording file compression storage method and system
CN109994131A
Data storage and search method, data storage and search system and computer readable storage medium
CN110908998A