File storage method and device and computer readable storage medium
By configuring configuration files for each application and determining the disk-loading strategy based on the importance of data, the IO load increase caused by frequent writes in the existing technology is solved, and the application-level disk-loading strategy refinement and overall planning of storage resources are realized, and system performance and IO efficiency are improved.
Patent Information
- Application Number
- CN202411783073.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-03-28
AI Technical Summary
The existing persistence technology causes system IO load to increase during frequent write operations, affecting system performance, and is difficult to meet the overall planning and control needs of multiple application platforms for storage resources.
By preconfiguring the configuration file for each application, determining the target drop-out strategy based on the application's data importance, and selecting the appropriate storage method based on the strategy, the application-level drop-out strategy refinement is achieved, thereby optimizing the system's IO state and the use of storage resources.
It improves the IO status of the system, reduces the overall IO pressure of the system, makes the system performance more stable, and realizes the overall control and planning of storage resources on multiple application platforms.
Smart Images

Figure CN119718196A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of data storage, and in particular to a file storage method, device, and computer-readable storage medium. Background Art
[0002] In the embedded and automotive fields, persistence technology is a very important technology, which is used to support the non-volatile storage needs of the business.
[0003] At present, there are some technologies on the market that can meet the non-volatile storage needs of businesses. However, existing persistence technologies all write the data generated by the application directly to the disk for persistent storage, which will cause the system to perform frequent write operations, increase the system IO load, and affect system performance. Summary of the invention
[0004] In order to solve the above technical problem or at least partially solve the above technical problem, at least one embodiment of the present disclosure provides a file storage method, device and computer-readable storage medium.
[0005] In a first aspect, the present disclosure provides a file storage method, comprising:
[0006] In response to receiving the file to be stored of the target application, obtaining a configuration file corresponding to the target application;
[0007] Obtaining a target disk placement strategy corresponding to the target application from the configuration file, wherein the disk placement strategy is related to the importance of application data, and different disk placement strategies correspond to different data storage methods;
[0008] Based on the target disk placement strategy, the file to be stored is stored.
[0009] In a second aspect, the present disclosure provides a file storage device, comprising:
[0010] A first acquisition module, configured to acquire a configuration file corresponding to the target application in response to receiving a file to be stored of the target application;
[0011] A second acquisition module is used to obtain a target disk placement strategy corresponding to the target application from the configuration file, wherein the disk placement strategy is related to the importance of application data, and different disk placement strategies correspond to different data storage methods;
[0012] A storage module is used to store the files to be stored based on the target disk placement strategy.
[0013] In a third aspect, the present disclosure provides an electronic device, including: a processor and a memory;
[0014] The processor is used to execute any of the file storage methods provided by the embodiments of the present disclosure by calling the program or instruction stored in the memory.
[0015] In a fourth aspect, the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores a program or instruction, wherein the program or instruction enables a computer to execute any of the file storage methods provided in the embodiments of the present disclosure.
[0016] In a fifth aspect, the present disclosure provides a computer program product, which is used to execute any of the file storage methods provided by the embodiments of the present disclosure.
[0017] In a sixth aspect, the present disclosure provides a vehicle, comprising the file storage device as described in the second aspect, or the electronic device as described in the third aspect, or the computer-readable storage medium as described in the fourth aspect, or the computer program product as described in the fifth aspect.
[0018] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has at least the following advantages:
[0019] In the disclosed embodiment, in response to receiving the files to be stored of the target application, a configuration file corresponding to the target application is obtained, and the target disk placement strategy corresponding to the target application is obtained from the configuration file, wherein the disk placement strategy is related to the importance of the data of the application, and different disk placement strategies correspond to different data storage methods, and then based on the target disk placement strategy, the files to be stored are stored. The above technical solution is adopted, by configuring the corresponding disk placement strategy for each application using the configuration file, and then when the files to be stored of the application are received, the appropriate way to store the files is selected based on the disk placement strategy corresponding to the application, thereby realizing the refinement of the application-level disk placement strategy, which is conducive to improving the IO state of the entire system, reducing the overall IO pressure of the system, and making the system performance more stable. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0021] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0022] Figure 1 A flowchart of a file storage method provided by an exemplary embodiment of the present disclosure;
[0023] Figure 2 A flowchart of a file storage method provided for another exemplary embodiment of the present disclosure;
[0024] Figure 3 A schematic diagram showing the relationship between the SQLite persistence layer, the db interface abstraction layer and the optimization layer of an exemplary embodiment of the present disclosure is shown;
[0025] Figure 4 A timing diagram of an exemplary embodiment of the present disclosure is shown;
[0026] Figure 5 A schematic diagram showing the relationship between various modules of the optimization layer of an exemplary embodiment of the present disclosure is shown;
[0027] Figure 6 A schematic diagram of the structure of a file storage device provided in one embodiment of the present disclosure. DETAILED DESCRIPTION
[0028] In order to more clearly understand the above-mentioned purposes, features and advantages of the present disclosure, the present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It is understandable that the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments, and the specific embodiments described herein are only used to explain the present disclosure, rather than to limit the present disclosure. In the absence of conflict, the embodiments of the present disclosure and the features in the embodiments can be combined with each other. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in the field belong to the scope of protection of the present disclosure.
[0029] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0030] Before explaining the specific implementation methods of the present disclosure, the Chinese and English technical terms that may be involved in the present disclosure are explained as follows:
[0031] SQLite: An open source lightweight database widely used in the embedded field;
[0032] vector-per: a persistence technology that complies with automotive software specifications;
[0033] AUTOSAR: AUTomotive Open System ARchitecture, an automotive open system architecture alliance, is a software specification in the automotive field;
[0034] IO: Input and output, in this disclosure, refers to the input and output of files;
[0035] WAL mode: Write Ahead Logging, which is a mechanism used in many databases to implement atomic transactions. This feature was introduced in SQLite 3.7.0. In WAL mode, in addition to the .db file (a lightweight database file that can be used to store and manage data), SQLite also contains two files, namely .wal file and .shm file. The former is a log file and the latter is a log index file.
[0036] At present, there are some technologies on the market that can meet the non-volatile storage needs of businesses. Existing persistence technologies all write the data generated by the application directly to the disk for persistent storage, which will cause the system to perform frequent write operations, increase the system IO load, and affect system performance.
[0037] In addition, for some multi-application embedded platforms and operating systems, in addition to meeting conventional non-volatile storage requirements, they also expect that the storage resources used by applications can be planned and controlled as a whole; from the perspective of system optimization, there needs to be better conversion efficiency between IO volume and persistence capability, and the overall IO volume should also be controlled. However, the existing persistence solution that directly writes whatever data comes to the disk makes the IO efficiency low, and the existing persistence technology is also difficult to meet the above-mentioned IO volume control and improve IO efficiency system optimization requirements.
[0038] In response to the above problems, the present disclosure provides a file storage method, which pre-configures a corresponding configuration file for each application, and uses the configuration file to control the application's file disk placement strategy, the disk quota that each application can use when persisting, etc., so that the system has the ability to centrally control the storage space, making the storage resources of multiple application platforms as a whole controllable and plannable, and can optimize the system's IO efficiency, reduce the system's overall IO pressure, and make the system have more reliable and better IO performance. The solution of the present disclosure builds its own write and read cache, and establishes a set of read and write strategies on it, which has better query and write efficiency under the same system architecture. After testing, the overall IO efficiency of this solution is better than the vector-per technology.
[0039] The specific implementation of the file storage method, device and computer-readable storage medium disclosed in the present invention is explained in detail below with reference to the accompanying drawings.
[0040] Figure 1A flowchart of a file storage method provided for an exemplary embodiment of the present disclosure is provided. The method can be executed by a file storage device provided by an embodiment of the present disclosure. The file storage device can be implemented by software and / or hardware and can be integrated in an electronic device, specifically, can be integrated in an operating system or an embedded system of the electronic device. The system (including the operating system and the embedded system) can manage multiple applications and has a memory and a disk for storing related data of multiple applications. A database engine (such as SQLite) is also integrated in the operating system to implement different applications in combination with the solution of the present disclosure, and store the data generated by the application in a disk or memory according to the disk placement strategy corresponding to the application.
[0041] like Figure 1 As shown, the file storage method may include the following steps:
[0042] Step 101: in response to receiving a file to be stored of a target application, obtaining a configuration file corresponding to the target application.
[0043] The configuration file can be configured by the developer in advance according to the data storage requirements of the application. The configuration file can record one or more configuration information such as the disk placement strategy, available disk quota, and the size of the read cache and write cache configured for the application. Through the configuration file, the overall management and planning of storage resources can be achieved to prevent the application from overusing disk resources and making the system unstable. At the same time, the overall management of the disk placement strategy and read and write cache is achieved, which helps to reduce the IO pressure in the system and improve IO efficiency.
[0044] In the embodiment of the present disclosure, when a file to be stored of a target application (which may be any application installed in an electronic device) is received, a configuration file corresponding to the target application may be obtained.
[0045] For example, when configuring a corresponding configuration file for each application, a one-to-one correspondence between the application identifier and the configuration file can be established. Then, when the application has data (recorded in the form of a file) that needs to be written, the configuration file corresponding to the application can be obtained by querying the application identifier of the application.
[0046] It should be noted that when this solution is applied to different fields, the way of receiving files is different. For example, in the automotive field, the files to be stored in the application can be received through the Autosar interface.
[0047] Step 102: Obtain a target disk placement strategy corresponding to the target application from the configuration file, wherein the disk placement strategy is related to the importance of application data, and different disk placement strategies correspond to different data storage methods.
[0048] In the disclosed embodiment, after obtaining the configuration file corresponding to the target application, the configuration file may be parsed to obtain the disk placement strategy (referred to as the target disk placement strategy) corresponding to the target application from the configuration file.
[0049] As an example, the configuration file can be in JSON format. Developers can configure the configuration files of each application through the configuration interface. For example, the configuration file can include the sync_to_storage_strategy field. The value of this field represents the disk placement strategy configured for the application. Different values represent different disk placement strategies. For example, the value of this field is 1, which represents the first disk placement strategy, the value of 2 represents the second disk placement strategy, and the value of 3 represents the third disk placement strategy. Therefore, by obtaining the value of this field in the configuration file, the target disk placement strategy corresponding to the target application can be determined.
[0050] Among them, different disk placement strategies correspond to different data storage methods. The disk placement strategy is related to the data importance of the application. For example, for applications with high data importance, if you want to ensure data security when the system loses power or crashes, you can configure the application's disk placement strategy to be direct disk placement; for applications with low data importance, there is no need to persist the data of these applications, so you can configure the disk placement strategy corresponding to these applications to not be placed on disk, that is, the data is only cached in memory.
[0051] Step 103: store the file to be stored based on the target disk placement strategy.
[0052] In the embodiment of the present disclosure, after the target disk placement strategy is determined, the files to be stored can be stored based on the target disk placement strategy.
[0053] As an example, when the target disk placement strategy is the first disk placement strategy, the first disk placement strategy is to trigger the disk placement when the disk placement conditions are met. Then, when storing the files to be stored based on the target disk placement strategy, the files to be stored can be stored in the write cache area first. When the disk placement conditions are met, the disk placement operation is triggered to store the files in the write cache area to the disk, thereby completing the data placement.
[0054] As an example, when the target disk placement strategy is the second disk placement strategy, the second disk placement strategy is to directly place the received data on the disk. That is to say, each time the application writes data, it will trigger the placement on the disk. Then, when storing the files to be stored based on the target disk placement strategy, the files to be stored can be directly stored on the disk to achieve persistent storage of the data and ensure the security of the data.
[0055] As an example, when the target disk placement strategy is the third disk placement strategy, the third disk placement strategy is to store received data in memory, that is, the data written by the application is only stored through the memory, the data will not be placed on the disk, and the application also reads the data from the memory. Then, when storing the files to be stored based on the target disk placement strategy, the files to be stored can be stored in the memory cache area.
[0056] Each application has different requirements for data storage. The present disclosure sets a suitable disk drop strategy for each application in advance according to its own needs and expectations. For example, if the application attaches importance to the security of data when the system loses power or crashes, then the disk drop strategy can be set to the second disk drop strategy (that is, each data is written to the disk, and frequent writing will cause the IO load to increase, but the security is good); if the application attaches more importance to performance, the disk drop strategy can be set to the first disk drop strategy (first cache the data in the write cache area, and then drop it to the disk when the disk drop conditions are met, and most IO interacts with the cache); if the application only wants to cache data, the disk drop strategy can be set to the third disk drop strategy (no disk drop, no persistence function). Therefore, by pre-configuring the corresponding disk drop strategy for each application through the configuration file, and then dropping the data written by the application to the disk or memory based on the disk drop strategy, the application-level disk drop strategy is refined, which is conducive to improving the IO status of the entire system, while reducing the overall IO pressure of the system, making its performance more stable.
[0057] The file storage method of the disclosed embodiment, in response to receiving the file to be stored of the target application, obtains the configuration file corresponding to the target application, obtains the target disk placement strategy corresponding to the target application from the configuration file, and then stores the file to be stored based on the target disk placement strategy. The above technical solution is adopted, by configuring the corresponding disk placement strategy for each application using the configuration file, and then when receiving the file to be stored of the application, the appropriate way to store the file is selected based on the disk placement strategy corresponding to the application, thereby realizing the refinement of the application-level disk placement strategy, which is conducive to improving the IO state of the entire system, reducing the overall IO pressure of the system, and making the system performance more stable.
[0058] In an optional embodiment of the present disclosure, Figure 2 As shown, based on the above embodiment, when the target disk placement strategy obtained is the first disk placement strategy, that is, the data written by the target application needs to be written to the disk only when the storage condition is met, in this case, step 103 may include the following sub-steps:
[0059] Step 201: store the file to be stored in a write buffer area.
[0060] The capacity of the write cache area can be configured through a configuration file. For example, the configuration file may include a write_cache_max_capacity_kb field, the value of which is the size of the configured write cache area in kb. It is understandable that for applications that need to cache written data, a write cache area and the size of the write cache area can be set for it through a configuration file, so that each data written by the application will enter the write cache area.
[0061] In the disclosed embodiment, for applications configured with the first disk placement strategy, the written data (i.e., the files to be stored) will be cached in the corresponding write cache area, thereby reducing the system IO amount to a certain extent, thereby alleviating the IO pressure of the entire system.
[0062] Step 202: Determine a disk placement condition based on the configuration file.
[0063] In the disclosed embodiment, when the target disk placement strategy is the first disk placement strategy, the disk placement conditions that trigger the disk placement can also be pre-configured in the configuration file. Then, when the application writes data, the disk placement conditions corresponding to the application are determined based on the configuration file, and the disk placement is triggered only when the disk placement conditions are met.
[0064] The placement conditions may include at least one of the following conditions:
[0065] The amount of data cached in the write cache area reaches the data amount threshold;
[0066] The time interval from the last disk placement reaches the preset disk placement interval;
[0067] The data volume threshold and disk flushing interval are obtained from the configuration file.
[0068] That is to say, the configuration file can pre-configure the disk placement condition as the amount of data cached in the write cache area reaches the data volume threshold; or, the configuration file can pre-configure the disk placement condition as the time interval from the last disk placement reaches the preset disk placement interval; or, the configuration file can pre-configure the disk placement condition as the amount of data cached in the write cache area reaches the data volume threshold, or, the time interval from the last disk placement reaches the preset disk placement interval. In other words, when two disk placement conditions are configured, the disk placement is triggered when one of the disk placement conditions is met.
[0069] Exemplarily, the configuration file may include a sync_to_storage_interval field (in milliseconds) and / or a sync_to_storage_cache_threshold field (in kb), wherein the value of the sync_to_storage_interval field represents the configured disk drop interval, and when the time interval from the last disk drop reaches the value configured in the field, the disk drop is triggered; the value of the sync_to_storage_cache_threshold field represents the configured data volume threshold, and when the amount of data cached in the write cache reaches the value configured in the field, the disk drop is triggered. Therefore, in this embodiment, the values of the above two fields recorded in the configuration file can be obtained from the configuration file to determine the disk drop condition. For example, assuming that the value of the sync_to_storage_interval field in the configuration file is 30 milliseconds, it can be determined that the disk drop condition is that the time interval from the last disk drop reaches 30 milliseconds, that is, the disk drop is triggered every 30 milliseconds.
[0070] It should be noted that in the embodiment of the present disclosure, the execution order of step 201 and step 202 is not specific, and the two can be executed sequentially or simultaneously. Figure 2 The illustrated embodiment only takes step 202 being executed after step 201 as an example to explain the present disclosure, and is not intended to limit the present disclosure.
[0071] Step 203: based on the disk write condition, the files in the write cache area are stored in the disk according to the preset single write data volume.
[0072] In the embodiment of the present disclosure, after the conditions for placing the file on disk are determined, the files in the write cache area can be stored on the disk according to the preset single write data amount based on the conditions for placing the file on disk. That is to say, when the conditions for placing the file on disk are met, placing the file on disk can be triggered to write the files in the write cache area to the disk, and the amount of data written to the disk each time is the preset single write data amount.
[0073] Among them, the amount of data written at a single time can be pre-set according to actual needs. For example, the amount of data written at a single time can be determined according to the system's single IO upper limit (usually 4kb), and the amount of data written at a single time is set to be slightly less than or equal to the single IO upper limit. Since the size of the file that needs to be written by the application on the vehicle does not exceed 1kb, setting a larger amount of data written at a single time can increase the amount of data transferred in a single IO when it is written to the disk, thereby reducing the number of IO times and improving IO efficiency.
[0074] In an optional implementation of the present disclosure, when files in the write cache area are written to disk based on the disk-writing condition and according to the preset single-write data volume, the total data volume of the files in the write cache area can be obtained when the disk-writing condition is met, and the total data volume of the files in the write cache area can be compared with the preset single-write data volume. In the case where the total data volume of the files in the write cache area is less than the single-write data volume, the files in the write cache area are directly stored in the disk at one time, and all the files in the write cache area can be written to the disk through one IO operation; in the case where the total data volume of the files in the write cache area is greater than the single-write data volume, the files in the write cache area can be grouped according to the single-write data volume to obtain multiple file groups to be written, wherein the total data volume of each file group to be written is not greater than the single-write data volume, and then the multiple file groups to be written are stored in the disk in sequence, and a file in the file group to be written is written to the disk each time, so as to ensure that the data volume of the system single IO does not exceed its single IO upper limit.
[0075] The file storage method of this embodiment stores the files to be stored in the write cache area, determines the disk placement conditions based on the configuration file, and then stores the files in the write cache area to the disk according to the preset single write data amount based on the disk placement conditions. As a result, the data written by the application each time does not need to be written to the disk immediately, which can significantly reduce the IO amount. For the operating system, the IO amount is reduced, and the data amount transferred in a single IO is increased, which will greatly improve the performance of the disk IO; for the embedded system, it can reduce the number of disk flushing times and improve the performance of the storage chip.
[0076] For an application, the business data it generates may have different security requirements. Some data of the same application may need to ensure security when the system loses power or crashes, while other data may only need to be cached. In order to adapt to the different data security requirements of the same application, the solution disclosed in the present invention supports setting multiple disk placement strategies for the same application. Users can pre-configure appropriate disk placement strategies for different file types of the application in the configuration file according to the data security requirements of the application. The data recorded in files of different file types is different, and the corresponding data security requirements may be the same or different. In other words, multiple different file types can correspond to the same disk placement strategy or different disk placement strategies. Therefore, in an optional implementation of the present disclosure, when obtaining the target disk placement strategy corresponding to the target application from the configuration file, the number of disk placement strategies configured in the configuration file can be obtained first. If the number of disk placement strategies configured in the configuration file is one, then the disk placement strategy is the target disk placement strategy corresponding to the target application for the current file to be stored; if the number of disk placement strategies is multiple, each disk placement strategy and the file type corresponding to each disk placement strategy can be obtained from the configuration file, and then according to the file type of the file to be stored, the candidate disk placement strategy corresponding to the file type of the file to be stored is determined, and the candidate disk placement strategy is determined as the target disk placement strategy corresponding to the target application.
[0077] Exemplarily, the file naming format of the application can be predefined, and the file type can be marked in the file name. For example, the file naming format is "generation date_file type.format". Then, for the file to be stored, its file type can be determined from its file name, and then for the file to be stored, the target disk strategy corresponding to the target application can be determined according to the file type.
[0078] In this embodiment, by pre-configuring appropriate disk placement strategies for different file types for the same application through configuration files, different types of data generated by the application can be stored based on appropriate disk placement strategies, thereby realizing data-level disk placement strategy division, which is highly flexible and can further optimize the system's IO efficiency.
[0079] The solution disclosed in the present invention also supports the management and control of the disk quota that can be used by the application when persisting. The user can configure the available disk quota for the application in the configuration file. When the amount of data stored by the application on the disk exceeds the disk quota, the data can no longer be written to the disk. Therefore, in an optional implementation of the present invention, for the first disk placement strategy and the second disk placement strategy, before storing the file (the file in the write cache or the file to be stored) on the disk, the available disk quota corresponding to the target application can also be obtained from the configuration file, and the amount of stored data of the target application stored on the disk can be obtained to determine whether the amount of stored data has reached the available disk configuration. When the amount of stored data is less than the available disk quota, the operation of storing the file on the disk is performed.
[0080] Exemplarily, the configuration file may include a max_storage_capacity_kb field, the value of which indicates the available disk quota configured for the application, in kb. By obtaining the value of this field from the configuration file, the available disk quota corresponding to the application may be determined.
[0081] In the embodiment of the present disclosure, by configuring available disk quotas for applications in configuration files, centralized control of disk storage resources available to applications is achieved, which is beneficial to the stability of the system.
[0082] As an example, the solution disclosed in this disclosure can be implemented by improving SQLite, fully inheriting its advantages, and providing a file configuration interface to configure the disk placement strategy, disk available quota and other information corresponding to each application. Specifically, the SQLite persistence layer, db interface abstraction layer and optimization layer are created on the SQLite upper layer. The relationship between the three is as follows: Figure 3 As shown in the figure, the SQLite persistence layer implements the underlying persistence function; the db interface abstraction layer is responsible for shielding the underlying persistence implementation and providing a consistent interface to the upper layer; the optimization layer completes the overall functional expansion and enhancement, and provides an AUTOSAR standard persistence interface to the upper layer. The overall coordination timing diagram of the SQLite persistence layer, db interface abstraction layer and optimization layer is shown in the figure. Figure 4 As shown, from Figure 4 It can be seen that when the application passes the file to be stored, it is first processed by the optimization layer to determine the application's disk placement strategy and store the file based on the disk placement strategy. When the file needs to be placed on the disk, the SQLite interface of the SQLite persistence layer is called through the db interface abstraction layer to place the file on the disk, and then the SQLite persistence layer completes the underlying placement of the file. The optimization layer also returns the processing results to the application.
[0083] The specific implementation of SQLite persistence layer, db interface abstraction layer and optimization layer is introduced as follows:
[0084] (1) Implementation of SQLite persistence layer: This solution is based on the WAL mode, and SQLite release version 3.7.0 or later can be selected.
[0085] (2) Implementation of the db interface abstraction layer: This layer needs to encapsulate the SQLite persistence layer to provide a consistent interface. The specific implementation is not expanded here. The implementation logic of each interface is detailed as follows:
[0086] Initialize interface: completes the creation of the database and the establishment of basic tables;
[0087] GetValue: used to obtain a certain data in the database (i.e. disk), query the data by calling the SQLite interface of the SQLite persistence layer and return it to the previous layer;
[0088] GetValues: used to obtain multiple data from the database, query the data by calling the SQLite interface of the SQLite persistence layer and return it to the previous layer;
[0089] SetValues: used to store multiple data into the database, store data by calling the SQLite interface of the SQLite persistence layer, and return the execution result;
[0090] RemoveAllKeys: used to delete all data from the database, by calling the SQLite database, delete all data, and return the execution result;
[0091] RemoveKeys: used to delete multiple records from the database, by calling the SQLite database, delete multiple records, and return the execution result;
[0092] Remove: used to delete a specified piece of data from the database, delete the data by calling the SQLite database, and return the execution result;
[0093] The above interfaces together constitute a complete set of persistence operations, providing functions to the upper layer. The upper layer can complete operations on the SQLite database through the above interfaces.
[0094] (3) Implementation of the optimization layer: This layer completes the function expansion and enhancement through the db interface abstraction layer. This layer consists of three modules: configuration interface, AUTOSAR interface that supports the AUTOSAR standard, and read / write cache and disk placement strategy module. The write cache and disk placement strategy module executes different disk placement or cache decisions based on the configuration information given by the configuration interface. The relationship between the three modules is as follows: Figure 5 As shown, it should be understood that Figure 5The relationship shown is only an example and cannot be used as a limitation of the present disclosure. The three modules may also have other relationships as long as the solution of the present disclosure can be implemented.
[0095] The configuration interface accepts configuration files in JSON format. Users can use the configuration interface to configure the corresponding disk placement strategy, disk available quota and other configuration information for each application. For example, the configuration file is:
[0096]
[0097] In the above configuration file, the read_cache_max_capacity_kb field is used to configure the size of the application's read cache, in kb. The read cache is used to record data read from the disk, so that commonly used data can be directly accessed in the memory after being read from the disk without the need to read the disk IO again, which reduces the system's IO pressure to a certain extent. The data stored in the read cache is limited. When the read cache is full, the first data written in the read cache will be cleared to allow new data to be written. When the data read by the application is not cached in the read cache (for example, it has been cleared or has not been read from the disk), the data is read from the disk and cached in the read cache.
[0098] The sync_to_storage_strategy field is used to configure the application's disk placement strategy. This field has three possible values: PER_FSYNC_ALWAYS (the second disk placement strategy), PER_FSYNC_AUTO (the first disk placement strategy), and PER_FSYNC_NO (the third disk placement strategy). Among them, PER_FSYNC_ALWAYS: Each write is performed on the disk. This strategy will increase the overall load of disk IO, but it is highly secure and suitable for scenarios with high data security requirements; PER_FSYNC_AUTO: Automatically trigger the disk drop, which is determined by the disk drop threshold and the disk drop interval. When the time reaches the value configured in the "sync_to_storage_interval" field, the disk drop will be triggered. When the amount of data in the write cache reaches the data volume threshold configured in the sync_to_storage_cache_threshold field, the disk drop will also be triggered. This strategy greatly reduces the IO volume. For the operating system, reducing the IO volume and increasing the amount of data transferred in a single IO can greatly improve the performance of disk IO; for embedded platforms, it reduces the number of disk flushes and improves the performance of storage chips. PER_FSYNC_NO: In memory mode only, data will not be dropped to the disk.
[0099] The write_cache_max_capacity_kb field is used to configure the size of the application's write cache area, in kb. When the disk placement policy is set to PER_FSYNC_AUTO, the data written by the application will be cached in the write cache area, which can reduce the system's IO volume to a certain extent, thereby alleviating the IO pressure of the entire system.
[0100] The sync_to_storage_interval field is used to configure the interval for executing a storage flush. When the flush policy is set to PER_FSYNC_AUTO, a flush is triggered every time interval configured in this field.
[0101] The sync_to_storage_cache_threshold field is used to configure the data volume threshold for a write to disk. When the write to disk policy is set to PER_FSYNC_AUTO, the write to disk will be triggered when the amount of data in the write cache exceeds the data volume threshold configured in this field.
[0102] The max_storage_capacity_kb field is used to configure the available disk quota corresponding to the application. When the amount of application data stored on the disk exceeds the value configured in this field, the data cannot be written.
[0103] The AUTOSAR interface is a set of persistent operation interfaces specified by the AUTOSAR specification. The data files that the application needs to write are passed to the read-write cache and disk placement strategy module through this interface. After that, the read-write cache and disk placement strategy module obtains the configuration file corresponding to the application from the configuration interface, and determines the application's disk placement strategy based on the configuration file, configures the size of the application's read cache and write cache, and stores the received data files according to different disk placement strategies. Specifically, when the determined disk placement strategy is PER_FSYNC_ALWAYS, each written data will be directly dropped into the disk and trigger a disk flush, which can ensure that the data will not be lost as long as it is written; when the determined disk placement strategy is PER_FSYNC_AUTO, each written data will be first stored in the write cache until the amount of data in the write cache reaches the configured data volume threshold, or the disk placement time interval arrives, the disk placement will be triggered, and this disk placement strategy can greatly reduce the system's IO pressure; when the determined disk placement strategy is PER_FSYNC_NO, all writes and reads are performed in memory, and no disk operations are performed.
[0104] In summary, the solution disclosed in the present invention is conducive to improving the IO status of the entire system by refining the application-level disk placement strategy, while reducing the overall IO pressure of the system and making its performance more stable; and, by configuring the application's disk available quota through the configuration file, the storage resources of multiple application platforms can be managed and planned as a whole, which is conducive to the stability of the system.
[0105] In order to implement the above embodiments, the present disclosure further provides a file storage device, which can be implemented by software and / or hardware and can be integrated into an electronic device, specifically, an operating system or an embedded system of the electronic device.
[0106] Figure 6 A schematic diagram of the structure of a file storage device provided by an embodiment of the present disclosure is shown in FIG. Figure 6 As shown, the file storage device 30 may include: a first acquisition module 310 , a second acquisition module 320 and a storage module 330 .
[0107] The first acquisition module 310 is configured to acquire a configuration file corresponding to the target application in response to receiving a file to be stored of the target application;
[0108] A second acquisition module 320 is used to acquire a target disk placement strategy corresponding to the target application from the configuration file, wherein the disk placement strategy is related to the importance of application data, and different disk placement strategies correspond to different data storage methods;
[0109] The storage module 330 is used to store the files to be stored based on the target disk placement strategy.
[0110] Optionally, the target disk placement strategy is a first disk placement strategy, and the first disk placement strategy triggers disk placement when a disk placement condition is met; the storage module 330 includes:
[0111] A cache unit, used for storing the file to be stored in a write cache area;
[0112] A determination unit, configured to determine a disk placement condition based on the configuration file;
[0113] The disk placement unit is used to store the files in the write cache area into the disk based on the disk placement conditions and according to a preset single write data volume.
[0114] Further optionally, the placement condition includes at least one of the following conditions:
[0115] The amount of data cached in the write cache area reaches a data amount threshold;
[0116] The time interval from the last disk placement reaches the preset disk placement interval;
[0117] The data volume threshold and the disk flushing interval are obtained from the configuration file.
[0118] Further optionally, the tray placement unit is further used for:
[0119] When the write-to-disk condition is met, obtaining the total amount of data of the file in the write cache area;
[0120] In the case where the total amount of data is greater than the single-write data amount, the files in the write cache area are grouped to obtain a plurality of to-be-written file groups, wherein the total amount of data in each to-be-written file group is not greater than the single-write data amount;
[0121] The multiple file groups to be written are stored in the disk in sequence.
[0122] Optionally, the target disk placement strategy is a second disk placement strategy, and the second disk placement strategy is to directly place the received data on the disk; the storage module 330 is further used to:
[0123] The file to be stored is stored in a disk.
[0124] Optionally, the target disk placement strategy is a third disk placement strategy, and the third disk placement strategy is to store the received data in memory; the storage module 330 is further used to:
[0125] The file to be stored is stored in a memory buffer area.
[0126] Optionally, the second acquisition module 320 is further configured to:
[0127] Obtain the number of disk placement strategies configured in the configuration file;
[0128] In the case where there are multiple disk placement strategies, obtaining each disk placement strategy and a file type corresponding to each disk placement strategy from the configuration file;
[0129] Determine, according to the file type of the file to be stored, a candidate disk placement strategy corresponding to the file type of the file to be stored;
[0130] The candidate disk placement strategy is determined as the target disk placement strategy corresponding to the target application.
[0131] Optionally, the file storage device 30 further includes:
[0132] A third acquisition module is used to obtain the available disk quota corresponding to the target application from the configuration file;
[0133] A fourth acquisition module, used to acquire the amount of stored data of the target application stored in the disk;
[0134] The storage module 330 is further configured to: when the amount of stored data is less than the available quota of the disk, execute an operation of storing the file to the disk.
[0135] The file storage device applicable to electronic devices provided in the embodiments of the present disclosure can execute the file storage method provided in the embodiments of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method. For the contents not described in detail in the embodiments of the present disclosure, reference can be made to the description in any method embodiment of the present disclosure.
[0136] The present disclosure also provides an electronic device, including a processor and a memory; the processor calls the program or instructions stored in the memory to execute the steps of each embodiment of the file storage method as described in any of the above embodiments. To avoid repeated description, they are not repeated here.
[0137] The embodiments of the present disclosure also provide a computer-readable storage medium, which is non-transitory and stores programs or instructions. The programs or instructions enable a computer to execute the steps of each embodiment of the file storage method as described in any of the aforementioned embodiments. To avoid repeated description, they are not repeated here.
[0138] The embodiments of the present disclosure also provide a computer program product, which is used to execute the steps of each embodiment of the file storage method as described in any of the above embodiments.
[0139] An embodiment of the present disclosure also provides a vehicle, comprising a file storage device as described in any of the foregoing embodiments of the present disclosure, or an electronic device as described in any of the foregoing embodiments of the present disclosure, or a computer-readable storage medium as described in any of the foregoing embodiments of the present disclosure, or a computer program product as described in any of the foregoing embodiments of the present disclosure.
[0140] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0141] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A file storage method, characterized in that: The method comprises: In response to receiving the file to be stored of the target application, obtaining a configuration file corresponding to the target application; Obtaining a target disk placement strategy corresponding to the target application from the configuration file, wherein the disk placement strategy is related to the importance of application data, and different disk placement strategies correspond to different data storage methods; Based on the target disk placement strategy, the file to be stored is stored.
2. The method according to claim 1, characterized in that The target placement strategy is a first placement strategy, and the first placement strategy triggers placement when a placement condition is met; The storing the to-be-stored file based on the target disk placement strategy includes: Storing the file to be stored in a write buffer area; Determine a disk placement condition based on the configuration file; Based on the disk write condition, the files in the write cache area are stored in the disk according to the preset single write data volume.
3. The method according to claim 2, characterized in that The placement conditions include at least one of the following conditions: The amount of data cached in the write cache area reaches a data amount threshold; The time interval from the last disk placement reaches the preset disk placement interval; The data volume threshold and the disk flushing interval are obtained from the configuration file.
4. The method according to claim 2, characterized in that: Based on the disk write condition, storing the files in the write cache area to the disk according to a preset single write data amount includes: When the write-to-disk condition is met, obtaining the total amount of data of the file in the write cache area; In the case where the total amount of data is greater than the single-write data amount, the files in the write cache area are grouped to obtain a plurality of to-be-written file groups, wherein the total amount of data in each to-be-written file group is not greater than the single-write data amount; The multiple file groups to be written are stored in the disk in sequence.
5. The method according to claim 1, characterized in that The target disk placement strategy is the second disk placement strategy, and the second disk placement strategy is to directly place the received data on the disk; The storing the to-be-stored file based on the target disk placement strategy includes: The file to be stored is stored in a disk.
6. The method according to claim 1, characterized in that The target disk placement strategy is a third disk placement strategy, and the third disk placement strategy is to store the received data in memory; The storing the to-be-stored file based on the target disk placement strategy includes: The file to be stored is stored in a memory buffer area.
7. The method according to any one of claims 1 to 6, characterized in that: The acquiring the target disk placement strategy corresponding to the target application from the configuration file includes: Obtain the number of disk placement strategies configured in the configuration file; In the case where there are multiple disk placement strategies, obtaining each disk placement strategy and a file type corresponding to each disk placement strategy from the configuration file; Determine, according to the file type of the file to be stored, a candidate disk placement strategy corresponding to the file type of the file to be stored; The candidate disk placement strategy is determined as the target disk placement strategy corresponding to the target application.
8. The method according to any one of claims 2 to 5, characterized in that: Before storing the file in the disk, the method further includes: Obtaining the available disk quota corresponding to the target application from the configuration file; Acquire the amount of stored data of the target application stored in the disk; When the amount of stored data is less than the available quota of the disk, an operation of storing the file to the disk is performed.
9. A file storage device, characterized in that: include: A first acquisition module, configured to acquire a configuration file corresponding to the target application in response to receiving a file to be stored of the target application; A second acquisition module is used to obtain a target disk placement strategy corresponding to the target application from the configuration file, wherein the disk placement strategy is related to the importance of application data, and different disk placement strategies correspond to different data storage methods; A storage module is used to store the files to be stored based on the target disk placement strategy.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program or an instruction, and the program or the instruction enables a computer to execute the file storage method according to any one of claims 1 to 8.
Citation Information
Patent Citations
File storage method and device, computer device and storage medium
CN109857339A
File management method and device, computer equipment and storage medium
CN111198856A
File storage method and device, equipment and storage medium
CN114153806A
File compression storage method and device, storage medium and electronic equipment
CN117312260A
File storage method and device, electronic equipment and storage medium
CN117349234A