Configuration file parsing method and electronic device
Patent Information
- Application Number
- CN202511497038.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-20
- Publication Date
- 2026-02-27
- Estimated Expiration
- 2045-10-20
AI Technical Summary
When the business software starts up, the slow parsing speed of multiple storage processes on the configuration file results in a slow startup speed.
By using a shared memory mechanism, the storage process stores the parsed file data in shared memory. Subsequent storage processes can then quickly locate and verify the memory segment using the file identifier, avoiding repeated reading and parsing of configuration files from the disk.
This reduces the overall time spent by multiple storage processes parsing configuration files during startup, thus improving the startup speed of business software.
Smart Images

Figure CN120994624B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and particularly relates to a configuration file parsing method and an electronic device. BACKGROUND
[0002] For a multi-control storage system, a business software needs to read and parse a configuration file in a starting process, and configure the storage system according to the content in the configuration file. Since the content of the configuration file is relatively large, when the business software needs to read the content of the configuration file in a running process, the reading speed is relatively slow, and the efficiency is low. In particular, when the business software starts, multiple storage processes need to spend a lot of time to parse the configuration file, resulting in a relatively low starting speed of the business software.
[0003] Therefore, how to improve the parsing speed of the storage process on the configuration file when the business software starts, and further improve the starting speed of the business software is a problem to be solved at present. SUMMARY
[0004] The present application provides a configuration file parsing method and an electronic device to at least solve the problem of how to improve the parsing speed of the storage process on the configuration file when the business software starts, and further improve the starting speed of the business software in the related art.
[0005] The present application provides a configuration file parsing method, comprising:
[0006] obtaining a file identifier of a target configuration file to be read by a storage process, wherein the file identifier is constructed based on identifier information of the target configuration file and a file path for accessing a shared memory, and the shared memory is used to store file data obtained by a historical storage process by parsing the target configuration file, and the historical storage process is a process that initially needs to read the target configuration file before the storage process;
[0007] in response to being able to find a target memory segment identifier containing the file identifier in the shared memory, mapping a target memory segment corresponding to the target memory segment identifier to the storage process, so as to extract the file data from the target memory segment, wherein the target memory segment is a memory area in the shared memory for storing the file data;
[0008] in response to a verification result of the verification processing on the file data satisfying a preset verification condition, determining the file data as target data read by the storage process.
[0009] The present application also provides a configuration file parsing device, comprising:
[0010] The obtaining unit is configured to obtain a file identifier of a target configuration file that needs to be read by a storage process, wherein the file identifier is constructed based on identification information of the target configuration file and a file path for accessing the shared memory, and the shared memory is used to store file data obtained by a historical storage process by parsing the target configuration file, and the historical storage process is a process that needs to read the target configuration file for the first time before the storage process;
[0011] The mapping unit is configured to, in response to being able to find the target memory segment identifier containing the file identifier in the shared memory, map a target memory segment corresponding to the target memory segment identifier to the storage process, so as to extract the file data from the target memory segment, wherein the target memory segment is a memory area in the shared memory that stores the file data.
[0012] The determining unit is configured to, in response to a verification result of the verification processing on the file data satisfying a preset verification condition, determine the file data as target data read by the storage process.
[0013] The present application also provides an electronic device, comprising a memory configured to store a computer program, and a processor configured to execute the computer program to implement the steps of the configuration file parsing method.
[0014] The present application also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the configuration file parsing method.
[0015] The present application also provides a computer program product, comprising a computer program, and the computer program is executed by a processor to implement the steps of the configuration file parsing method.
[0016] The configuration file parsing method and the electronic device provided by the present application store the parsed file data in the shared memory by the first storage process that needs to read the configuration file, and provide a quick search based on the file identifier, a memory mapping, and a data verification mechanism for subsequent storage processes, so that the subsequent storage processes do not need to repeatedly perform time-consuming operations such as reading and parsing the configuration file from the disk, thereby reducing the overall time for the multiple storage processes to parse the configuration file in the startup phase, and effectively improving the startup speed of the business software. Therefore, the technical problem of how to improve the parsing speed of the storage process for the configuration file during the startup of the business software, and thereby improve the startup speed of the business software, can be solved, and the technical effects of improving the parsing speed of the storage process for the configuration file, and thereby improving the startup speed of the business software, can be achieved. BRIEF DESCRIPTION OF DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. Obviously, the drawings described below are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without any creative effort based on these drawings.
[0018] Figure 1 A flowchart of a configuration file parsing method provided by an embodiment of the present application is shown in FIG. 1.
[0019] Figure 2 A flowchart of reading configuration file data provided by an embodiment of the present application is shown in FIG. 2.
[0020] Figure 3 A structural diagram of a configuration file parsing device provided by an embodiment of the present application is shown in FIG. 3.
[0021] Figure 4 A structural diagram of another configuration file parsing device provided by an embodiment of the present application is shown in FIG. 4. DETAILED DESCRIPTION
[0022] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without any creative effort fall within the protection scope of the present application.
[0023] It should be noted that, in the description of the present application, the terms "comprise", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. The terms "first", "second" and the like in the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence.
[0024] In order to make the skilled in the art better understand the present application, the present application will be further described in detail below with reference to the drawings and specific embodiments.
[0025] The profile parsing method and the electronic device provided in the present application are at least applicable to a scenario in which multiple storage processes in a multi-control storage system need to repeatedly read the same configuration file. The storage process refers to a software process that executes specific business logic in the storage system. The process needs to obtain configuration information to complete system initialization or function adjustment during startup or running. In the related art, each storage process needs to independently read and parse the configuration file from the disk, resulting in high system Input / Output (I / O) load and low startup efficiency.
[0026] Figure 1 A flowchart of a configuration file parsing method provided for an embodiment of the present application is shown, and the method is described in detail in combination with the execution flow of the configuration file parsing method.
[0027] As Figure 1 shown, the configuration file parsing method includes the following steps.
[0028] In step 101, a file identifier of a target configuration file that needs to be read by a storage process is obtained, wherein the file identifier is constructed based on identification information of the target configuration file and a file path for accessing shared memory. The shared memory is used to store file data obtained by parsing the target configuration file by a historical storage process, which is a process that needs to read the target configuration file for the first time before the storage process.
[0029] In an embodiment of the present application, the target configuration file refers to a setup file required for the operation of the storage system, and its content includes but is not limited to key parameters such as CPU binding strategy, hardware support characteristics, or interrupt processing configuration. The file identifier is a unique identification symbol, which is constructed by combining the identification information of the target configuration file with a predefined file path. The identification information can be characteristic data such as the name, version number, or content hash value of the target configuration file; and the file path is an access path to the shared memory space of the storage system, which is used to locate the public memory area storing the historical parsing result.
[0030] The shared memory is a cross-process data sharing memory provided by the storage system, which has an efficient inter-process communication mechanism. Unlike the process private memory, it allows multiple storage processes to share the same memory area, and multiple storage processes can directly read and write data in the memory area without the need for data transmission through other intermediate media (such as disk or network), thereby greatly improving the efficiency of inter-process data sharing. Importantly, the data in the shared memory will not be released or tampered with due to the end, restart, or failure of a single storage process, and can be kept effective between multiple storage processes for a long time.
[0031] The history storage process refers to the first process that needs to read the target configuration file before the current storage process runs. The history storage process is responsible for completing the initial parsing of the target configuration file and writing the parsed results to shared memory, thereby providing data support for all subsequent storage processes that need to access the target configuration file, thus avoiding the repeated process of reading and parsing the target configuration file from the system disk by all storage processes.
[0032] It should be noted that the target configuration file is a specific configuration file that needs to be read and parsed by the current storage process in a specific business scenario. For example, when a storage process needs to enable the Network Attached Storage (NAS) feature, the corresponding NAS feature configuration file is the target configuration file of the storage process. The target configuration files required by different storage processes or the same storage process in different business stages may be different.
[0033] In step 102, in response to being able to find the target memory segment identifier containing the file identifier in the shared memory, the target memory segment corresponding to the target memory segment identifier is mapped to the storage process to extract file data from the target memory segment, wherein the target memory segment is a memory area in the shared memory that stores file data.
[0034] In an embodiment of the present application, the target memory segment identifier is information that uniquely identifies a specific memory area in the shared memory, used to identify the memory area that stores the file data of the target configuration file. Each memory area in the shared memory that stores specific data (such as the file data of a certain target configuration file) corresponds to a memory segment identifier. Through the memory segment identifier, the corresponding memory area can be accurately found, and mapping, reading, writing, and other operations can be performed on the memory area.
[0035] The target memory segment refers to the continuous address space in the shared memory that actually stores file data, and its internal content is organized according to a preset data structure. Through memory mapping technology, the storage process can directly read the data in the target memory segment without going through disk I / O operations. The file data is a structured data set obtained by parsing the target configuration file by the history storage process. The format of the file data includes but is not limited to key-value pairs, tree structures, or binary sequences, etc. machine-readable forms.
[0036] The target memory segment identifier is the memory segment identifier corresponding to the target configuration file required by the current storage process. When the storage process finds the corresponding target memory segment identifier in the shared memory through the file identifier, it means that the file data obtained by parsing the target configuration file by the history storage process has already been stored in the shared memory, and the current storage process does not need to read and parse the target configuration file from the system disk.
[0037] When it is determined that the target memory segment identifier exists, the storage process maps the target memory segment corresponding to the target memory segment identifier to its own address space. After the mapping is completed, the current storage process can directly extract file data from the target memory segment as if it were accessing its own private memory, without the need for disk I / O operations and repeated file parsing processes.
[0038] In step 103, in response to the verification result of the verification processing of the file data satisfying the preset verification condition, the file data is determined as target data read by the storage process.
[0039] In the embodiments of the present application, the verification processing includes, but is not limited to, checksum verification, version number comparison, data structure integrity check, and other security mechanisms, for ensuring that the data in the shared memory is not damaged or tampered with. The preset verification condition is a predefined verification pass threshold, which is a pre-set standard for judging whether the file data is valid, for example, a cyclic redundancy check code matching, a digital signature being valid, or a data length being within an expected range.
[0040] The target data is valid data of a target configuration file that the current storage process finally needs to obtain to complete its business function. When the result of the verification processing satisfies the preset verification condition, it means that the file data extracted from the target memory segment is complete, accurate, and reliable. At this time, the storage process determines the file data as the target data, and performs subsequent business operations based on the target data, for example, according to the CPU core binding information in the target data, the binding of the business module of the storage process and a specific CPU core is completed, to ensure the efficiency of business processing; or according to the advanced feature support information in the target data, the NAS, automatic layering, and other functions supported by the current model are enabled, to meet the business needs of the system.
[0041] The present application realizes cross-process reuse of configuration data through the shared memory mechanism, optimizes the disk reading and parsing operations performed by each process in the related art to be complete parsing performed only once by the first process, and verified data is directly obtained by subsequent processes through memory. This reduces repeated I / O operations and computing resource consumption, and in the scenario of frequent system restarts or fault recovery, can effectively accelerate the startup speed of business processes and improve the overall availability of the system. At the same time, by introducing a data verification link, efficient data sharing is realized on the premise of ensuring data reliability, and the consistency problem of configuration synchronization in a multi-process environment is solved.
[0042] In an implementation manner of the embodiment of the present application, after the file identifier of the target configuration file required to be read by the storage process is acquired, the corresponding target memory segment identifier can not be directly found in the shared memory in all cases. When the target memory segment identifier cannot be found, the target configuration file needs to be read and parsed from the system disk, and initial storage of the target configuration file data and construction of the associated identifier are completed, thereby providing a basis for subsequent storage process access to the target configuration file.
[0043] Specifically, the following method can be used, but is not limited to: in response to the target memory segment identifier not being found in the shared memory, the target configuration file is read from a preset database based on the storage process, wherein the preset database stores a plurality of configuration files; the target configuration file is subjected to file parsing processing to obtain file data, and the file data is stored in a first memory segment of the shared memory, wherein the first memory segment is any blank memory segment in the plurality of memory segments included in the shared memory; a first check code is generated based on the file data in the first memory segment, and the first check code is stored in the first memory segment; and a first memory segment identifier corresponding to the first memory segment is constructed according to the file identifier and the first memory segment information of the first memory segment.
[0044] In the embodiment of the present application, when the storage process cannot find the target memory segment identifier corresponding to the target configuration file in the shared memory, it indicates that the parsing result of the configuration file does not exist in the shared memory. At this time, a complete configuration file reading and parsing process needs to be performed, which guides the storage process to obtain the original configuration file from the preset database. The preset database is a storage medium used by the storage system to centrally manage all configuration files, and is usually located in the system disk or the non-volatile memory. It internally organizes and stores a plurality of configuration files in a specific directory structure or database table structure. The configuration file contains, but is not limited to, system hardware configuration parameters, function characteristic switch settings, or performance tuning parameters, and other key information.
[0045] After successfully reading the target configuration file from the preset database, the storage process will perform file parsing processing on the file content. File parsing processing refers to the process of converting a configuration file in text format or a specific encoding format into structured data available to a machine. The file parsing processing process includes, but is not limited to, syntax analysis, semantic parsing, data type conversion, and data integrity checking, and other processing stages. The file data obtained through parsing processing will be stored in a specific area of the shared memory, i.e., the first memory segment. The first memory segment refers to a blank memory area in the shared memory that is currently not occupied, and its capacity needs to be dynamically allocated or pre-set according to the size of the data after the configuration file is parsed. The shared memory is usually divided into a plurality of memory segments of the same size or different sizes to support the storage of the parsing results of a plurality of configuration files at the same time.
[0046] To ensure that the subsequent process can verify the correctness of the read data, a first check code is generated based on the file data stored in the first memory segment. The first check code is a digital fingerprint calculated by a preset check algorithm, and its generation principle is to perform mathematical operation on all bytes or specific fields of the file data to generate a unique code that can represent the characteristics of the data. Common check algorithms include but are not limited to cyclic redundancy check algorithm, hash function algorithm or message digest algorithm, etc. The generated first check code will be stored in a designated location of the same first memory segment, corresponding to the file data, to form a complete data storage unit.
[0047] Finally, the first memory segment identifier is constructed, and the first memory segment information includes but is not limited to the management metadata such as the start address of the memory segment, the segment size, and the access permission, and the first memory segment identifier is a unique identifier formed by binding the management metadata with the file identifier. The first memory segment identifier will be registered in the global management table of the shared memory, so that subsequent other storage processes can quickly locate the first memory segment through the same file identifier when reading the same configuration file, thereby realizing effective reuse of the parsing result.
[0048] The present application clearly states that when there is no required configuration data in the shared memory, the current process can independently complete the operations from reading, parsing to constructing the shared cache. At the same time, by persistently saving the parsing result in the shared memory, a reliable data sharing basis is established for subsequent storage processes. At the same time, the introduction of the check code provides a guarantee mechanism for data integrity, ensuring that even if the shared memory is accidentally modified, data anomalies can be discovered in time through the check mechanism, and on the premise of ensuring data reliability, the configuration parsing workload is minimized.
[0049] In one implementation manner of the embodiment of the present application, after completing the operation of mapping the target memory segment corresponding to the target memory segment identifier to the storage process and extracting the file data from the target memory segment, in order to ensure that the extracted file data is not damaged, tampered or data lost during the storage process in the shared memory, and to avoid the use of invalid data by the storage process leading to business initialization failure or abnormal running of the storage system, the file data also needs to be verified for reliability by the target check code.
[0050] Regarding the verification of the file data, the following methods can also be used but are not limited to: extracting the target check code corresponding to the file data from the target memory segment, wherein the target check code is a cyclic check code generated based on the historical storage process of storing the file data to the target memory segment; performing data verification processing on the file data based on the target check code to obtain a verification result.
[0051] In the embodiments of the present application, the target check code is a verification identifier generated by the historical storage process through a cyclic redundancy check algorithm when the file data is successfully stored in the target memory segment. The cyclic redundancy check algorithm is an error detection method for calculating the characteristic code of data through polynomial division, which can effectively identify bit errors, data tampering or storage medium abnormalities that may occur during data transmission or storage.
[0052] The storage location of the target check code is usually in the header or tail field of the target memory segment, and together with the file data, it constitutes a complete data storage structure. The generation process is to calculate all the bytes of the file data bit by bit, and finally get a fixed length check value, which is extremely sensitive to any subtle changes in data and can be regarded as a digital fingerprint of the file data.
[0053] After obtaining the target check code, the data verification process is started, which refers to the operation process of verifying the integrity of the current file data using the extracted target check code. In specific implementation, the same cyclic redundancy check algorithm as the historical storage process is used to recalculate the file data read from the target memory segment to generate a new temporary check code, i.e. the check code to be verified. Then the newly calculated temporary check code is compared with the previously extracted target check code, and the verification result is generated according to whether the two check codes are consistent.
[0054] The verification result is a state identifier representing the integrity of the data, and its judgment logic follows the pre-set matching rule. If the two check codes are completely consistent, it means that the file data has not been changed since it was written by the historical storage process, and the verification result is marked as a pass state; if there is any difference, it means that the file data may have been damaged due to memory errors, illegal access or hardware failure, etc., and the verification result is marked as a failure state.
[0055] The present application provides a guarantee for the reliability of data in shared memory through the verification mechanism based on cyclic redundancy check, at the same time, the verification process has small calculation overhead and high detection efficiency, does not affect the start-up speed of the storage process, and maintains the system performance advantage while ensuring data security.
[0056] In an implementation manner of the embodiment of the present application, in a case that the data verification processing based on the target check code is completed on the file data, and it is determined that the verification result does not satisfy the preset verification condition, it means that the file data stored in the current target memory segment has lost reliability, for example, data damage, tampering occurs due to system abnormality, memory access error and other problems in the long-term storage process of the shared memory, there is an incomplete writing condition when the historical storage process stores data at the beginning, and so on. If the file data is continued to be used, it will cause the deviation of the business initialization of the storage process, and even cause the business interruption of the multi-control storage system. Therefore, the data in the target memory segment needs to be repaired and updated to ensure that all storage processes that need to access the target configuration file can obtain complete and accurate file data.
[0057] Specifically, the following method can be used, but is not limited to: in response to the verification result not satisfying the preset verification condition, the storage process reads the target configuration file from the preset database, and performs file parsing processing on the target configuration file to obtain file data; the data in the target memory segment is deleted, and the file data is stored in the target memory segment; and a second check code is generated based on the file data in the target memory segment, and the second check code is stored in the target memory segment.
[0058] In the embodiment of the present application, when the verification result confirms that the preset verification condition is not satisfied, the storage process needs to be guided to read the target configuration file from the preset database again. After successfully reading the target configuration file, the storage process will start a complete file parsing processing flow. The file parsing processing process includes but is not limited to multiple stages such as syntax analysis, semantic parsing and data structure conversion, to ensure that the configuration file in text format or specific encoding format is converted into structured file data that can be directly used by the system. Unlike the initial parsing, this parsing is performed under the premise that the data may be damaged, so more strict syntax checking rules or more complete exception handling mechanisms are used to exclude any factors that may cause data abnormalities.
[0059] After the reliable file data is obtained by completing the file parsing, the memory data updating operation is performed, and all existing data in the target memory segment is completely deleted. The deletion operation not only empties the data content, but also resets the memory segment index and metadata, to ensure that there is no invalid information that may affect the new data. Subsequently, the file data obtained by re-parsing is completely written into the emptied target memory segment. The writing process follows the preset memory writing protocol to ensure that the storage format of the data in the shared memory conforms to the data structure specification.
[0060] After the file data is successfully written into the target memory segment, a second check code is generated based on the new data. The second check code is a verification code recalculated using the same cyclic redundancy check algorithm as before, and its generation process covers the complete content of all file data in the target memory segment. The second check code has a strict correspondence with the file data, and any subsequent data modification will cause the check codes to mismatch. The newly generated second check code is stored in a designated location of the target memory segment, together with the file data to form the updated complete data unit.
[0061] The data recovery mechanism of the present application ensures the reliability of the configuration file data in the shared memory. When data anomalies are detected, instead of simply abandoning the use of shared memory, the normal state of the shared memory is restored by actively rebuilding the data, which not only solves the data needs of the current process, but also eliminates data obstacles for subsequent other processes. In the scenario of continuous operation and high availability requirement of the multi-control storage system, the system failure caused by a single data error can be effectively avoided, and the long-time stable operation of the storage service is guaranteed.
[0062] In an implementation manner of an embodiment of the present application, when the file data is verified based on the target check code, the following manner can be used but is not limited to: generating a to-be-verified check code based on the storage process according to the file data; performing check code matching processing according to the target check code and the to-be-verified check code to obtain a check code matching result; in response to the check code matching result being that the target check code and the to-be-verified check code do not match, obtaining a first verification result, wherein the first verification result does not satisfy a preset verification condition; and in response to the check code matching result being that the target check code and the to-be-verified check code match, obtaining a second verification result, wherein the verification result includes the first verification result and the second verification result, and the second verification result satisfies the preset verification condition.
[0063] In an embodiment of the present application, the to-be-verified check code is a temporary verification identifier calculated in real time by the current storage process according to the file data extracted from the target memory segment through a specified check algorithm. The algorithm used to generate the to-be-verified check code is exactly the same as the algorithm used by the historical storage process to generate the target check code, for example, the cyclic redundancy check algorithm, to ensure that the two check codes are comparable under the same data condition. The calculation process covers all byte contents of the file data, and any slight data change will cause the to-be-verified check code generated finally to change significantly.
[0064] Subsequently, check code matching processing is performed, which is an analysis process of accurately comparing the target check code with the to-be-verified check code. The comparison operation usually uses mechanisms such as bit-by-bit comparison or hash value comparison to ensure that any difference between the two check codes can be identified sensitively. The final check code matching result is a binary state identifier that explicitly records whether the two check codes are exactly the same.
[0065] When the check code matching result shows that the target check code does not match the check code to be verified, a first verification result is generated. The first verification result indicates that the file data read from the shared memory is inconsistent with the original file data stored, which may be caused by memory bit flipping, unauthorized modification operation or data transmission error, etc. The first verification result is compiled into a verification failure status signal, which does not meet the preset verification condition, at this time the current file data read from the shared memory will not be used, and the corresponding data recovery or reconstruction process will be triggered.
[0066] On the contrary, when the check code matching result confirms that the target check code completely matches the check code to be verified, a second verification result is generated. The second verification result indicates that the file data in the shared memory has maintained the original state since being stored, and has not been damaged or tampered in any form. The second verification result is compiled into a verification pass status signal, which completely meets the preset verification condition, at this time the file data read from the shared memory is regarded as reliable and valid data, which can be directly used by the storage process.
[0067] The verification result generation process of the present application constitutes a complete data reliability evaluation system. The verification result is used as a decision basis to determine whether to accept the data in the shared memory or to start an alternative data acquisition scheme. Through the fine verification result distinction, different processing strategies can be adopted for file data in different quality states, which ensures the reliability of the file data and avoids unnecessary repeated parsing operations.
[0068] In one implementation manner of the embodiment of the present application, when performing file parsing processing on the target configuration file, the following manner can be adopted, but is not limited to: identifying the text encoding format and the structured syntax rule of the target configuration file; performing byte stream decoding on the target configuration file based on the text encoding format to obtain a standard character stream, performing syntax analysis on the standard character stream according to the structured syntax rule, and constructing a configuration option tree for representing the hierarchical relationship of the configuration items in the target configuration file; serializing the configuration option tree into a serialized data stream satisfying a preset data format, wherein the preset data format is a data format decoupled from the structured syntax rule; and determining the serialized data stream as the file data, wherein the file data can be directly parsed and used by any process supporting the preset data format.
[0069] In the embodiments of the present application, the purpose of the file parsing process is to convert the original target configuration file into a structured data form that can be directly used by multiple storage processes. When performing the file parsing process, it is necessary to identify the text encoding format and the structured syntax rule of the target configuration file. The text encoding format refers to the character encoding scheme adopted by the target configuration file when stored, for example: 8-bit Unicode Transformation Format (UTF-8), American Standard Code for Information Interchange (ASCII), or GBK, etc. The text encoding format determines the way of converting the byte sequence in the file into readable text characters. The structured syntax rule defines the organization structure and semantic specification of the configuration file, for example: the key-value pair hierarchy of JavaScript Object Notation (JSON) format, the tag nesting of eXtensible Markup Language (XML) format, or the section attribute of Initialization File (INI) format. The structured syntax rule ensures that the content of the configuration file has a clear logical relationship and is analyzable.
[0070] After identifying the text encoding format, the target configuration file is subjected to byte stream decoding operation based on the text encoding format. Byte stream decoding is the process of converting the original data in the target configuration file into a standard character stream according to a specific encoding rule, which eliminates the problem of garbled characters or parsing errors caused by encoding differences. The standard character stream is a continuous data stream composed of uniformly encoded characters, and its content completely retains the original information of the configuration file, but presents it in a standardized form, laying a foundation for subsequent syntax analysis.
[0071] The standard character stream is subjected to syntax analysis according to the identified structured syntax rule. Syntax analysis is the process of analyzing the structure of the standard character stream layer by layer and extracting semantic information. Through lexical analysis and syntax analysis techniques, configuration items, attribute values, and their associated relationships are identified. The analysis result is constructed into a configuration option tree, which is a tree-shaped data structure. The nodes of the configuration option tree represent the configuration items in the configuration file, and the parent-child relationship represents the hierarchical inclusion or dependency relationship between the configuration items. This tree structure directly reflects the logical organization of the configuration content, making the query and maintenance of complex configuration relationships more efficient.
[0072] To further enhance the generality and access efficiency of the data, the configuration option tree is serialized into a serialized data stream satisfying a preset data format. Serialization refers to the process of converting a tree-shaped data structure in memory into a continuous byte sequence for storage or transmission. The preset data format is a general data representation form decoupled from the original structured syntax rules, for example, a custom binary format characterized by being directly readable without relying on a specific syntax parser. The serialized data stream is the byte sequence generated after serialization, which retains all the information of the configuration option tree.
[0073] The application determines the serialized data stream as file data for use by the storage process. Since the file data adopts the preset data format, it has high portability and can be directly parsed and used by any process supporting the preset data format without repeated syntax parsing or encoding conversion. This significantly improves data sharing efficiency. In the multi-process environment of the multi-control storage system, different processes only need to have the same deserialization logic to quickly obtain configuration information, avoiding the overhead of repeated parsing, while ensuring the consistency of configuration data between different components.
[0074] In one implementation manner of the embodiment of the application, when mapping the target memory segment identified by the target memory segment to the storage process, the following implementation manners can be used, but are not limited to: mapping the target memory segment to the address space of the storage process in read-only mode to obtain a read-only pointer pointing to the starting address of the target memory segment; accessing the file data in the target memory segment through the read-only pointer and copying the file data to the memory of the storage process.
[0075] In the embodiment of the application, the read-only mode is a memory protection mechanism that allows the storage process to read memory data but prohibits any modification operation. This mode is implemented through the memory protection flag provided by the system to ensure that the correct read-only permission attribute is set during the mapping process. The address space is a virtual memory range allocated for each storage process, and the storage process can access the mapped physical memory region through the address space.
[0076] After completing the mapping operation, a read-only pointer pointing to the starting address of the target memory segment is obtained. The read-only pointer is a special memory address reference whose type is limited to the read-only attribute. Any operation that attempts to modify the memory content through the read-only pointer will be blocked and trigger a memory protection exception. The starting address refers to the first byte position of the target memory segment in the shared memory region, through which the complete memory segment content can be located.
[0077] After obtaining the read-only pointer, the storage process accesses the file data in the target memory segment through the read-only pointer. At this time, the storage process is allowed to directly read the content in the shared memory, but due to the limitation of the read-only permission, it is ensured that the original data will not be accidentally modified or damaged. During the access process, a complete data reading operation is performed to transfer the file data from the shared memory area to the temporary buffer of the storage process.
[0078] Finally, the read file data is copied to the private memory of the storage process, which is a memory area independently owned by the storage process and isolated from other storage processes. The storage process can freely read and write data in this memory area without affecting the original content of the shared memory. The copy operation creates an independent copy of the file data, so that the storage process can perform any operation on the copy without worrying about damaging the integrity of the shared data source.
[0079] The present application prevents concurrent write conflicts that may occur in a multi-process environment by combining read-only mapping and data copying, ensuring the stability and consistency of the configuration file data in the shared memory. At the same time, by copying the data to the private memory of the process, the storage process can freely use and modify the configuration data locally, meeting the individual processing needs, without affecting the access of other storage processes to the original shared data.
[0080] In one implementation manner of the embodiment of the present application, in the process of realizing efficient reuse of file data based on shared memory, the total capacity of the shared memory as a system-level public memory resource is fixed and limited. As the storage system runs for a long time, more and more file data will be stored in different memory segments of the shared memory. If the usage state of the shared memory is not managed, the available space of the shared memory will gradually decrease, and even the memory will be exhausted. At this time, when a new storage process needs to store the parsed target configuration file data, it will not be able to find a blank memory segment and can only repeatedly perform the operation of reading and parsing the configuration file from the preset database. Therefore, it is necessary to dynamically monitor the shared memory and clean up the memory segments to maintain a reasonable usage rate of the shared memory and ensure that it always has enough blank memory segments for new data storage.
[0081] Specifically, the following methods can also be used, but are not limited to: monitoring the memory usage rate of the shared memory, and the access frequency and last access time of each of the plurality of memory segments in the shared memory; in response to the memory usage rate being greater than a preset usage rate threshold, determining a candidate memory segment to be data-cleared from the plurality of memory segments based on the access frequency and the last access time; performing a data cleaning operation on the candidate memory segment, and determining the candidate memory segment after data cleaning as a blank memory segment of the shared memory.
[0082] In the embodiments of the present application, the memory usage rate refers to the proportion of the currently occupied shared memory capacity to the total shared memory capacity, reflecting the tension degree of the shared memory resource. The access frequency refers to the number of times that the memory segment is accessed by the storage process in a unit of time, embodying the activity degree of the stored data in the memory segment. The last access time records the time stamp of the last time that each memory segment is accessed by the storage process, for identifying the idle memory segment that has not been used for a long time.
[0083] The preset usage threshold is a critical value preset according to the actual memory capacity and usage demand, for example, any value between 70% and 90%, for triggering the memory cleaning operation. Based on the access frequency and the last access time of each memory segment, the candidate memory segment to be data-cleared is determined in multiple memory segments. The selection logic is: the memory segment with lower access frequency and earlier last access time is given priority, and this type of memory segment usually stores historical configuration data that is no longer frequently used, and it is determined as the cleaning object, which has the least impact on system running.
[0084] After the candidate memory segment is determined, the data cleaning operation is performed on the candidate memory segment, which not only includes cleaning the file data and the corresponding check code stored in the memory segment, but also includes resetting the management metadata and the state identifier of the memory segment, to ensure that the memory segment returns to the initial state that can be reallocated. The cleaning process can use a safe data erasing method to prevent the residual of sensitive configuration information.
[0085] After the data cleaning is completed, the processed candidate memory segment is re-determined as a blank memory segment of the shared memory. The blank memory segment refers to a memory area whose content has been emptied and is in a usable state, which can be re-occupied by new configuration file parsing data. The recycling of the blank memory segment alleviates the storage pressure of the shared memory and creates necessary conditions for the storage of new configuration data.
[0086] The dynamic memory management of the present application ensures the sustainable utilization of the shared memory resource, realizes the efficient turnover of the storage space under the condition of limited memory resource through continuous monitoring and intelligent cleaning, avoids the failure caused by memory depletion, and ensures that the high-frequency access configuration data can be long-term resident in the shared memory.
[0087] In an implementation manner of the embodiment of the present application, when the storage process needs to access the target configuration file through the shared memory quickly, the premise is that the file data corresponding to the target configuration file and the associated file identifier exist in the shared memory, and the generation of the file identifier is not completed by the storage process that needs to access currently, but is completed by the historical storage process that contacts the target configuration file earlier. The original reading of the target configuration file and the generation of the file identifier are completed by the historical storage process in advance, which provides a unique index for all subsequent storage processes to locate the file data in the shared memory, and avoids the repeated execution of the original configuration file reading and identifier construction operation by each storage process.
[0088] Specifically, the following methods can be used, but are not limited to: in response to the need of the historical storage process to read the target configuration file, reading the target configuration file and the identifier information corresponding to the target configuration file from the preset database based on the historical storage process; obtaining the file path of the shared memory, and performing data combination processing on the identifier information and the file path to obtain the file identifier.
[0089] In the embodiment of the present application, the historical storage process, as the first process to access the target configuration file, undertakes the role of initializing the shared memory data. When it is detected that the historical storage process needs to read the target configuration file, the historical storage process is guided to obtain the required target configuration file from the preset database.
[0090] The historical storage process not only reads the content data of the target configuration file from the preset database, but also obtains the identifier information corresponding to the target configuration file. The identifier information is characteristic data used to distinguish different configuration files, and can include the name, version number, content hash value or other unique identifier of the configuration file. The identifier information and the configuration file content are associated with each other, and together constitute a complete metadata set of the configuration file.
[0091] After successfully obtaining the target configuration file and its identifier information, the access path of the shared memory needs to be determined. The file path is a path to the shared memory area, which is determined when the shared memory is initialized, and usually appears as a virtual file system path or a special path reserved by the system. The file path remains unique and consistent in the entire multi-control storage system, ensuring that all storage processes can access the same shared memory area through the same path.
[0092] After obtaining the file path, the identifier information and the file path are combined for data processing. Data combination processing is an operation process of combining multiple data elements into a single identifier, and the specific implementation manners include but are not limited to string splicing, hash calculation or encoding conversion processing methods.
[0093] In addition to the above, the file identifier can also be generated in the following manner: when the first historical storage process (e.g., process1) that needs to access the target configuration file (e.g., config_file1) starts to execute, a unique file identifier (e.g., shm_key) is generated according to the existing file path and the identifier information of the target configuration file, which is used to identify the shared memory, and the file data obtained by parsing the configuration file is saved in the shared memory.
[0094] The file identifier can be constructed in the following manner: shm_key1 = ftok(“ / compass”, 1); wherein “ / compass” represents the file path, 1 represents the identifier information, and ftok represents a data combination processing instruction or algorithm.
[0095] Similarly, when the process process1 needs to access other configuration files (e.g., config_file2), a unique file identifier shm_key2 can be generated for the config_file2 file in the following manner:
[0096] shm_key2 = ftok(“ / compass”, 2).
[0097] The file identifier obtained through data combination processing in the present application is an identifier with sufficient uniqueness and stability, which establishes a definite association between the target configuration file and the corresponding storage location in the shared memory. In the subsequent storage process access, the file identifier can quickly locate the stored configuration file data in the shared memory, avoiding the overhead of repeated parsing, and laying a solid foundation for the efficient operation of the entire multi-control storage system.
[0098] In one implementation manner of the embodiment of the present application, after the historical storage process obtains the file identifier corresponding to the target configuration file through data combination processing, a dedicated memory area needs to be allocated in the shared memory for the target configuration file to store the parsed file data, and a unique identifier bound to the memory area is constructed to ensure that the subsequent storage process can accurately locate the memory area through the file identifier.
[0099] Specifically, the following method can also be used, but is not limited thereto: determining a second memory segment in the shared memory according to a preset region size, wherein the second memory segment is any blank memory segment in the plurality of memory segments included in the shared memory, and the region size of the second memory segment is the preset region size; determining the second memory segment as a target memory segment, and combining data according to the file identifier and target memory segment information of the target memory segment to construct a target memory segment identifier corresponding to the target memory segment, wherein the target memory segment information at least includes the region size and attribute information corresponding to the target memory segment.
[0100] In the embodiments of the present application, the preset region size is a predefined fixed memory allocation unit, the value of which is generally determined according to the average size of the configuration file and the expected data volume, so as to ensure that most configuration files can be completely stored, while avoiding excessive waste of memory space.
[0101] By sharing the memory management allocation, a second memory segment is selected from a plurality of available memory segments as a storage container for configuration data. The second memory segment refers to a continuous storage area in the shared memory address space, which has a capacity strictly meeting the requirement of the preset region size and is currently in an unallocated state of a blank memory segment. The second memory segment has complete read and write permissions and an initialized storage state, and can be directly used to receive configuration file data.
[0102] After determining the second memory segment, it is formally determined as a target memory segment, that is, a specific memory area used for storing file data parsed from the current configuration file. In order to establish the mapping relationship between the file identifier and the physical storage location, a corresponding target memory segment identifier needs to be constructed. The construction process is based on data combination of the file identifier and the target memory segment information of the target memory segment. The target memory segment information is a set of metadata describing the characteristics of the memory segment, at least including the region size and the attribute information corresponding to the target memory segment. The attribute information covers the access permission, creation time, and recent modification time of the memory segment, and other management attributes, which together constitute the complete description of the memory segment.
[0103] By a specific data combination algorithm, the file identifier and the target memory segment information are fused to generate the target memory segment identifier. The target memory segment identifier is indexed and recorded in the global management table of the shared memory, so that any subsequent storage process that needs to access the configuration file can quickly locate the corresponding target memory segment through the same file identifier.
[0104] Specifically, the form of the target memory segment identifier can be represented by, but is not limited to, the following way:
[0105] shm_id = shmget(shm_key, 4096, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
[0106] Wherein, shm_id represents the target memory segment identifier, shmget is the instruction of data combination or the preset data combination algorithm, 4096 represents the region size, and S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP represents the attribute information.
[0107] The application solves the mapping relationship maintenance problem between the configuration file and the storage location by constructing the target memory segment identifier, and provides a solid foundation guarantee for efficient data sharing in a multi-process environment. The whole memory allocation and identifier construction process ensures the standardization and scalability of shared memory management, and creates favorable conditions for long-term stable operation of the multi-control storage system.
[0108] In an implementable manner of an embodiment of the application, after the historical storage process completes the construction of the target memory segment identifier corresponding to the target memory segment, although a dedicated storage area (i.e., the target memory segment) has been determined for the current target configuration file in the shared memory, the target memory segment is still in a blank state without valid data, and cannot provide data support for subsequent storage processes that need to access the target configuration file. Therefore, the historical storage process must further complete the storage operation of the file data and the target check code, and convert the valid information of the original configuration file into reliable data that can be directly reused in the shared memory.
[0109] Specifically, the following methods can be used, but are not limited to: storing the file data into the target memory segment; generating the target check code based on the file data in the target memory segment, and storing the target check code into the target memory segment.
[0110] In an embodiment of the application, the file data that has undergone complete parsing processing is stored into the allocated target memory segment. The storage process follows a specific memory writing protocol to ensure that the data is stored in order according to the preset structure. The file data is stored in the memory in a serialized format, and its storage location is arranged continuously from the starting address of the target memory segment, fully utilizing the storage space of the preset area size, while reserving the necessary header area for storing management information.
[0111] After completing the storage of the file data, the target check code is generated based on the file data in the target memory segment. The generation process uses a cyclic redundancy check algorithm to calculate the file data stored in the target memory segment bit by bit. This calculation process covers all the contents from the starting position to the ending position of the file data, ensuring that any change in any bit of data will cause significant changes in the final generated check value.
[0112] After generating the target check code, it is stored in a specified location of the target memory segment. This specified location is usually located after the file data storage area or in the reserved header structure, and together with the file data forms a complete data storage unit. When storing, it is necessary to ensure that the target check code is physically adjacent to the corresponding file data, but logically separated, so as to facilitate quick positioning and extraction of the check information during subsequent reading.
[0113] Specifically, regarding the data structure of the file data and the target check code stored in the target memory segment, the following methods can be used, but are not limited to:
[0114] struct shm_data_info {
[0115] uint32 content_crc;
[0116] char config_file_info
[4096] ;
[0117] }
[0118] Wherein, uint32 content_crc represents the target check code, and char config_file_info represents file data.
[0119] The application stores the file data and the target check code in the same target memory segment, establishes a complete data credibility guarantee system, so that any subsequent storage process can obtain the original data and the check code when accessing the configuration data, and then quickly and effectively verify the data integrity. The reliability of data reading is improved, and frequent access to the preset database is avoided, and the overall performance of the multi-control storage system is improved.
[0120] In an implementable manner of an embodiment of the application, to realize fast access to the target configuration file, the storage process first needs to obtain the file identifier corresponding to the target configuration file, but the file identifier cannot be obtained every time. If the file identifier has been generated for the target configuration file by a previous storage process, the file identifier is directly reused; if not, it needs to be reconstructed.
[0121] Specifically, the following methods can be used, but are not limited to: in response to the need of the storage process to obtain the target configuration file, data searching is performed in the preset identifier library based on the identifier information corresponding to the target configuration file, and a searching result is obtained; in response to the searching result being the file identifier corresponding to the identifier information, the file identifier is extracted; in response to the searching result being that the file identifier corresponding to the identifier information is not found, the file path of the shared memory is obtained, the identifier information and the file path are combined and processed to obtain the file identifier, and the file identifier is stored in the preset identifier library.
[0122] In an embodiment of the application, when the storage process needs to obtain the target configuration file, data searching is first performed in the preset identifier library based on the identifier information corresponding to the target configuration file. The preset identifier library is a database for managing file identifiers, which can be a memory database, a hash table or an index structure in persistent storage. Its core function is to maintain the mapping relationship between the identifier information and the file identifier, so as to quickly retrieve and reuse the existing identifier.
[0123] The record matched with the identification information is searched in the preset identification library through a query algorithm (such as a hash search or a binary search) to obtain a search result, the search result is a state identification, and it is explicitly indicated whether the corresponding file identification is found in the preset identification library. If the search result is that the file identification corresponding to the identification information is successfully found, the file identification is directly extracted.
[0124] If the search result is that the file identification corresponding to the identification information is not found, it is indicated that the target configuration file is accessed for the first time or is not recorded in the identification library, and the generation process of the file identification needs to be performed. At this time, the file path of the shared memory is obtained, and then the identification information is combined with the file path to generate the file identification, and the generated file identification is immediately stored in the preset identification library.
[0125] The application reduces the calculation overhead of identification generation through efficient management and reuse of the file identification. Meanwhile, the global consistency of the file identification is ensured, and the identification conflict or repetition problem that may occur in a multi-process environment is avoided, thereby laying a solid foundation for stable access to the shared memory.
[0126] In an implementable manner of the embodiment of the application, in order to facilitate understanding of the process of reading the file data of the configuration file by the multi-storage process, the application provides a flowchart of reading the configuration file data, as shown in Figure 2 As shown in the figure, when the storage process needs to read the configuration file, the storage process first obtains the shm_key corresponding to the configuration file, that is, the file identification, and then searches the shared memory segment shm_id corresponding to the configuration file, that is, the target memory segment identification, through shmget, and then maps the target memory segment corresponding to the shm_id to the address space of the current storage process. The storage process directly accesses the file data in the target memory segment, and if the target check code matches the file data content at this time, it is indicated that the file data in the shared memory is valid configuration file data, and the configuration file data can be directly obtained. If the target check code does not match the file data content at this time, it is indicated that the file data in the target memory segment corresponding to the shm_id is not credible, and at this time, the configuration file needs to be read from the system disk, parsed, and then written into the target memory segment, and the target check code is updated to the target memory segment again.
[0127] Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and a general hardware platform as required, and of course, it can also be realized by hardware, but in many cases, the former is a better implementation manner.
[0128] The embodiment of the application further provides a configuration file parsing device, Figure 3 A structural diagram of the configuration file parsing device provided by the application is shown in Figure 3As shown, comprising:
[0129] The acquisition unit 31 is configured to acquire a file identifier of a target configuration file required to be read by the storage process, wherein the file identifier is constructed based on identification information of the target configuration file and a file path for accessing the shared memory, and the shared memory is configured to store file data obtained by a historical storage process by parsing the target configuration file, and the historical storage process is a process that initially requires to read the target configuration file before the storage process;
[0130] The mapping unit 32 is configured to, in response to being able to find the target memory segment identifier containing the file identifier in the shared memory, map a target memory segment corresponding to the target memory segment identifier to the storage process, so as to extract the file data from the target memory segment, wherein the target memory segment is a memory area of the shared memory for storing the file data.
[0131] The determination unit 33 is configured to, in response to a verification result of the verification processing on the file data satisfying a preset verification condition, determine the file data as target data read by the storage process.
[0132] In an embodiment of the present application, as shown in Figure 4 The configuration file parsing device further comprises:
[0133] The reading unit 34 is configured to, in response to being unable to find the target memory segment identifier in the shared memory, read the target configuration file from a preset database based on the storage process, wherein the preset database stores a plurality of configuration files.
[0134] The parsing unit 35 is configured to perform file parsing processing on the target configuration file to obtain file data.
[0135] The storage unit 36 is configured to store the file data into a first memory segment of the shared memory, wherein the first memory segment is any blank memory segment in a plurality of memory segments included in the shared memory.
[0136] The generation unit 37 is configured to generate a first check code based on the file data in the first memory segment.
[0137] The storage unit 36 is further configured to store the first check code into the first memory segment.
[0138] The construction unit 38 is configured to construct a first memory segment identifier corresponding to the first memory segment according to the file identifier and first memory segment information of the first memory segment.
[0139] In an embodiment of the present application, as shown in Figure 4 The configuration file parsing device further comprises a verification unit 39, and the verification unit 39 is configured to:
[0140] extracting a target check code corresponding to the file data from the target memory segment, wherein the target check code is a cyclic check code generated based on a historical storage process of storing file data into the target memory segment;
[0141] performing data verification processing on the file data based on the target check code to obtain a verification result.
[0142] In an embodiment of the present application, the reading unit 34 is further configured to, in response to the verification result not satisfying the preset verification condition, read the target configuration file from the preset database based on the storage process;
[0143] The parsing unit 35 is further configured to perform file parsing processing on the target configuration file to obtain file data.
[0144] The storage unit 36 is further configured to, after deleting the data in the target memory segment, store the file data into the target memory segment.
[0145] The generating unit 37 is further configured to generate a second check code based on the file data in the target memory segment and store the second check code into the target memory segment.
[0146] In an embodiment of the present application, the verification unit 39 is specifically configured to:
[0147] generate a to-be-verified check code based on the storage process according to the file data;
[0148] perform check code matching processing on the target check code and the to-be-verified check code to obtain a check code matching result;
[0149] in response to the check code matching result being that the target check code does not match the to-be-verified check code, obtain a first verification result, wherein the first verification result does not satisfy the preset verification condition;
[0150] in response to the check code matching result being that the target check code matches the to-be-verified check code, obtain a second verification result, wherein the verification result includes the first verification result and the second verification result, and the second verification result satisfies the preset verification condition.
[0151] In an embodiment of the present application, the parsing unit 35 is specifically configured to:
[0152] identify a text encoding format and a structured syntax rule of the target configuration file;
[0153] perform byte stream decoding on the target configuration file based on the text encoding format to obtain a standard character stream, perform syntax parsing on the standard character stream based on the structured syntax rule, and construct a configuration option tree for representing a configuration item hierarchical relationship in the target configuration file;
[0154] The configuration option tree is serialized into a serialized data stream satisfying a preset data format, wherein the preset data format is a data format decoupled from a structured syntax rule;
[0155] The serialized data stream is determined as file data, wherein the file data can be directly parsed and used by any process supporting the preset data format.
[0156] In an embodiment of the present application, the mapping unit 32 is specifically configured to:
[0157] mapping the target memory segment to the address space of the storage process in a read-only mode to obtain a read-only pointer pointing to the start address of the target memory segment;
[0158] accessing the file data in the target memory segment through the read-only pointer and copying the file data to the memory of the storage process.
[0159] In an embodiment of the present application, the determining unit 33 is further configured to:
[0160] monitoring the memory usage of the shared memory, and the respective access frequency and last access time of each of the plurality of memory segments in the shared memory;
[0161] in response to the memory usage being greater than a preset usage threshold, determining a candidate memory segment to be data-cleared from the plurality of memory segments based on the access frequency and the last access time;
[0162] performing a data clearing operation on the candidate memory segment, and determining the candidate memory segment after data clearing as a blank memory segment of the shared memory.
[0163] In an embodiment of the present application, the generating unit 37 is further configured to:
[0164] in response to the historical storage process needing to read the target configuration file, reading the target configuration file and the identification information corresponding to the target configuration file from the preset database based on the historical storage process;
[0165] obtaining the file path of the shared memory, and performing data combination processing on the identification information and the file path to obtain a file identification.
[0166] In an embodiment of the present application, the generating unit 37 is further configured to:
[0167] determining a second memory segment in the shared memory according to a preset region size, wherein the second memory segment is any blank memory segment in a plurality of memory segments included in the shared memory, and the region size of the second memory segment is the preset region size;
[0168] The second memory segment is determined as a target memory segment, data is combined according to a file identifier and target memory segment information of the target memory segment to construct a target memory segment identifier corresponding to the target memory segment, wherein the target memory segment information at least includes a region size and attribute information corresponding to the target memory segment.
[0169] In an embodiment of the present application, the generating unit 37 is further configured to:
[0170] store the file data into the target memory segment;
[0171] generate a target check code based on the file data in the target memory segment, and store the target check code into the target memory segment.
[0172] In an embodiment of the present application, the obtaining unit 31 is further configured to:
[0173] in response to a storage process requiring to obtain a target configuration file, performing data searching in a preset identifier library based on identifier information corresponding to the target configuration file to obtain a searching result;
[0174] in response to the searching result being a file identifier corresponding to the identifier information being found, extracting the file identifier;
[0175] in response to the searching result being the file identifier corresponding to the identifier information not being found, obtaining a file path of the shared memory, performing data combination processing on the identifier information and the file path to obtain the file identifier, and storing the file identifier into the preset identifier library.
[0176] The description of the features in the embodiment of the configuration file parsing device can refer to the related description of the embodiment of the configuration file parsing method, which will not be repeated here.
[0177] Embodiments of the present application also provide an electronic device, including a memory and a processor, the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any of the above configuration file parsing method embodiments.
[0178] Embodiments of the present application also provide a computer readable storage medium, which stores a computer program, wherein the computer program is configured to execute the steps in any of the above configuration file parsing method embodiments when running.
[0179] In an exemplary embodiment, the above computer readable storage medium can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store computer programs.
[0180] Embodiments of the present application further provide a computer program product comprising a computer program which, when executed by a processor, implements the steps of any of the above-described configuration file parsing method embodiments.
[0181] Embodiments of the present application further provide another computer program product comprising a non-transitory computer readable storage medium storing a computer program which, when executed by a processor, implements the steps of any of the above-described configuration file parsing method embodiments.
[0182] Those skilled in the art will further appreciate that the units and algorithm steps of the examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or both, and that the implementation decisions are within the skill of an ordinary designer of such products. To clearly illustrate the interchangeability of hardware and software, and to avoid obscuring the disclosure with details of particular implementations, the descriptions herein have generally been stated in terms of various functional processes embodying the examples. The steps of the examples are not, however, necessarily limited to this scope so as to specifically require the steps to be performed in the order illustrated, or to require all of the steps to be performed, in order to achieve the desired results. It will be appreciated that the steps of the examples can be performed in any order, or in parallel, unless otherwise specifically noted. It will also be appreciated that certain steps can be omitted, or other steps added, without departing from the scope of the present disclosure.
[0183] The above provides a configuration file parsing method and an electronic device. The principles and implementation manners of the present application are described by applying specific examples. The above descriptions of the examples are only used to help understand the method of the present application and its core idea. It should be noted that, for those skilled in the art, without departing from the principles of the present application, some improvements and modifications can be made to the present application. These improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A method for parsing a configuration file, characterized in that, include: Obtain the file identifier of the target configuration file that the storage process needs to read, wherein the file identifier is constructed based on the identification information of the target configuration file and the file path used to access the shared memory, the shared memory is used to store the file data obtained by the previous storage process from parsing the target configuration file, and the previous storage process is the process that first needed to read the target configuration file before the current storage process; In response to the ability to find a target memory segment identifier containing the file identifier in the shared memory, the target memory segment corresponding to the target memory segment identifier is mapped to the storage process to extract the file data from the target memory segment, wherein the target memory segment is a memory region in the shared memory that stores the file data; In response to the verification result of the file data verification process meeting the preset verification conditions, the file data is determined as the target data read by the storage process; In response to the inability to find the target memory segment identifier in the shared memory, the target configuration file is read from a preset database based on the storage process, wherein the preset database stores multiple configuration files; The target configuration file is parsed to obtain the file data, and the file data is stored in the first memory segment of the shared memory, wherein the first memory segment is any blank memory segment among the multiple memory segments included in the shared memory; A first verification code is generated based on the file data in the first memory segment, and the first verification code is stored in the first memory segment; The first memory segment identifier corresponding to the first memory segment is constructed based on the file identifier and the first memory segment information of the first memory segment.
2. The configuration file parsing method according to claim 1, characterized in that, After mapping the target memory segment corresponding to the target memory segment identifier to the storage process to extract the file data from the target memory segment, the method further includes: Extract the target checksum corresponding to the file data from the target memory segment, wherein the target checksum is a loop checksum generated after the file data is stored in the target memory segment by the historical storage process; The file data is verified based on the target checksum to obtain the verification result.
3. The configuration file parsing method according to claim 2, characterized in that, After performing data verification processing on the file data based on the target checksum to obtain the verification result, the method further includes: In response to the verification result not meeting the preset verification conditions, the target configuration file is read from the preset database based on the storage process, and the target configuration file is parsed to obtain the file data; After deleting the data in the target memory segment, the file data is stored in the target memory segment; A second checksum is generated based on the file data in the target memory segment, and the second checksum is stored in the target memory segment.
4. The configuration file parsing method according to claim 2, characterized in that, The data verification process based on the target checksum to obtain the verification result includes: Based on the storage process, a verification code to be verified is generated according to the file data. The target check code is matched with the check code to be verified to obtain the check code matching result. In response to the verification code matching result indicating that the target verification code does not match the verification code to be verified, a first verification result is obtained, wherein the first verification result does not satisfy the preset verification condition; In response to the verification code matching result being that the target verification code matches the verification code to be verified, a second verification result is obtained, wherein the verification result includes the first verification result and the second verification result, and the second verification result satisfies the preset verification condition.
5. The configuration file parsing method according to claim 1, characterized in that, The process of parsing the target configuration file to obtain the file data includes: Identify the text encoding format and structured syntax rules of the target configuration file; The target configuration file is decoded into a byte stream based on the text encoding format to obtain a standard character stream. The standard character stream is then parsed according to the structured syntax rules to construct a configuration option tree that represents the hierarchical relationship of configuration items in the target configuration file. The configuration option tree is serialized into a serialized data stream that meets a preset data format, wherein the preset data format is a data format decoupled from the structured syntax rules; The serialized data stream is identified as the file data, wherein the file data can be directly parsed and used by any process that supports the preset data format.
6. The configuration file parsing method according to claim 1, characterized in that, The step of mapping the target memory segment corresponding to the target memory segment identifier to the storage process, so as to extract the file data from the target memory segment, includes: The target memory segment is mapped to the address space of the storage process in read-only mode to obtain a read-only pointer to the starting address of the target memory segment; The file data in the target memory segment is accessed through the read-only pointer, and the file data is copied into the memory of the storage process.
7. The configuration file parsing method according to claim 1, characterized in that, The method further includes: Monitor the memory usage rate of the shared memory, as well as the access frequency and last access time of each of the multiple memory segments in the shared memory; In response to the memory usage rate being greater than a preset usage rate threshold, a candidate memory segment to be cleared is determined from the plurality of memory segments based on the access frequency and the last access time; Perform a data clearing operation on the candidate memory segment, and determine the candidate memory segment after data clearing as the blank memory segment of the shared memory.
8. The configuration file parsing method according to claim 2, characterized in that, The method further includes: In response to the historical storage process needing to read the target configuration file, the historical storage process reads the target configuration file and the corresponding identification information from a preset database. Obtain the file path of the shared memory, and perform data combination processing on the identification information and the file path to obtain the file identifier; A second memory segment is determined in the shared memory according to a preset region size, wherein the second memory segment is any blank memory segment among the multiple memory segments included in the shared memory, and the region size of the second memory segment is the preset region size; The second memory segment is determined as the target memory segment. Data is combined according to the file identifier and the target memory segment information to construct the target memory segment identifier corresponding to the target memory segment. The target memory segment information includes at least the region size and the attribute information corresponding to the target memory segment.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the configuration file parsing method as described in any one of claims 1 to 8 when executing the computer program.
Citation Information
Patent Citations
Method, server and system for sharing resource data
CN104980454A
Data file processing method and system
CN106708825A