Data storage method and device and electronic equipment
By storing data in multiple storage spaces and setting storage capacity thresholds, the problem of data deletion in the prior art resulting in historical data loss is solved, and more efficient data storage and utilization are achieved.
Patent Information
- Application Number
- CN202411505728.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-03-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When the prior art deletes stored data and stores new data, it may lead to more stored data being deleted, resulting in the loss of historical data and low utilization of storage media.
By storing data in multiple storage spaces and setting a maximum storage capacity threshold in each storage space, when one storage space reaches the threshold, new data is written to the adjacent next storage space instead of directly deleting the stored data.
This method can retain as much historical data as possible without affecting the historical data of other storage spaces and improve the utilization rate of storage media.
Smart Images

Figure CN119690332A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and more specifically, to a data storage method, device and electronic device. Background Art
[0002] At present, with the development of electronic information technology, data can be stored in the storage space of a storage medium. Although the data stored in the storage space can be deleted, so as to use the storage space to store new data, the current method of deleting the stored data and storing new data may result in more stored data being deleted. Summary of the invention
[0003] The present application proposes a data storage method, device and electronic device.
[0004] In a first aspect, an embodiment of the present application provides a data storage method, comprising: in response to a file write request, obtaining data to be written and index information, wherein the index information comprises multiple file numbers and a first position parameter, the multiple file numbers correspond one-to-one to multiple storage spaces, the first position parameter is used to characterize the file number corresponding to the first storage space most recently written, and the first storage space is one of the multiple storage spaces; obtaining a first data amount of data currently stored in the first storage space corresponding to the first position parameter; when the first data amount is equal to a first threshold, taking the next position parameter adjacent to the first position parameter as a first target position, wherein the first threshold is used to characterize the maximum storage capacity corresponding to the first storage space; writing the data to be written to the target storage space corresponding to the first target position, and updating the first position parameter in the index information to the first target position.
[0005] Optionally, for a possible implementation, when the first data amount is equal to a first threshold, the next position parameter adjacent to the first position parameter is used as the first target position, including: when the first data amount is equal to the first threshold, adding 1 to the first position parameter to obtain a first numerical value; and taking the remainder after dividing the first numerical value by a second threshold as the first target position, wherein the second threshold is the amount of storage space.
[0006] Optionally, for a possible implementation, each storage space is divided into multiple package data spaces, and the index information also includes a second position parameter and a specified package data space sequence number, wherein the second position parameter is used to represent the file sequence number corresponding to the second storage space most recently read, and the method also includes: in response to a data read request, determining the second storage space corresponding to the second position parameter; determining the specified package data space corresponding to the specified package data space sequence number in the second storage space; reading the data stored in the specified package data space; and updating the specified package data space sequence number in the index information to the next package data space sequence number adjacent to the specified package data space sequence number.
[0007] Optionally, for a possible implementation, updating the specified packet data space sequence number in the index information to the next packet data space sequence number adjacent to the specified packet data space sequence number includes: when the specified packet data space sequence number is a third threshold, using the next position parameter adjacent to the second position parameter as the second target position, wherein the third threshold is the maximum value of the packet data space sequence number corresponding to the packet data space in the second storage space; updating the second position parameter in the index information to the second target position, and updating the specified packet data space sequence number in the index information to the initial address.
[0008] Optionally, for a possible implementation, when the designated packet data space sequence number is a third threshold, the next position parameter adjacent to the second position parameter is used as the second target position, including: when the designated packet data sequence number is the third threshold, adding 1 to the second position parameter to obtain a second value; and using the remainder after dividing the second value by the second threshold as the second target position, wherein the second threshold is the amount of storage space.
[0009] Optionally, for a possible implementation, the obtaining of the data to be written and the index information in response to a file write request includes: determining one file write request in sequence from a write request sequence as a target file write request, wherein the write request sequence includes multiple file write requests; obtaining the data to be written and the index information in response to the target file write request; after writing the data to be written to the target storage space corresponding to the first target position and updating the first position parameter in the index information to the first target position, the step further includes: returning to execute the step of determining one file write request in sequence from the write request sequence as a target file write request and subsequent steps, until each file write request in the write request sequence is taken as the target file write request.
[0010] Optionally, for a possible implementation, before determining in sequence a file write request as a target file write request from the write request sequence, it also includes: obtaining an initial data set; dividing the initial data set based on a fourth threshold to obtain multiple data to be written and an arrangement order of each data to be written, each data to be written corresponds to a file write request, wherein the fourth threshold is used to characterize the storage capacity of each package data space in the storage space; arranging multiple file write requests in the arrangement order of the data to be written corresponding to each file write request to obtain the write request sequence.
[0011] Optionally, for a possible implementation, obtaining the data to be written and the index information in response to a file write request includes: obtaining the data to be written in response to a file write request; obtaining the index information from a first index file; and obtaining the index information from a second index file if the index information is not successfully obtained from the first index file, wherein the second index file is a backup file of the first index file.
[0012] Optionally, for a possible implementation, writing the data to be written into the target storage space corresponding to the first target position includes: deleting the data stored in the target storage space corresponding to the first target position; and writing the data to be written into the target storage space corresponding to the first target position.
[0013] In the second aspect, the embodiment of the present application also provides a data storage device, including: a first acquisition unit, a second acquisition unit, a first target position determination unit and a writing unit. The first acquisition unit is used to respond to a file write request, obtain the data to be written and index information, wherein the index information includes multiple file numbers and a first position parameter, the multiple file numbers correspond to multiple storage spaces one by one, the first position parameter is used to represent the file number corresponding to the first storage space written most recently, and the first storage space is one of the multiple storage spaces; the second acquisition unit is used to obtain the first data volume of the data currently stored in the first storage space corresponding to the first position parameter; the first target position determination unit is used to use the next position parameter adjacent to the first position parameter as the first target position when the first data volume is equal to a first threshold, wherein the first threshold is used to represent the maximum storage capacity corresponding to the first storage space; the writing unit is used to write the data to be written into the target storage space corresponding to the first target position, and update the first position parameter in the index information to the first target position.
[0014] In a third aspect, an embodiment of the present application further provides an electronic device comprising: one or more processors; a memory; and one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method described in the first aspect.
[0015] The data storage method, device and electronic device provided by the embodiment of the present application first respond to a file write request, obtain the data to be written and index information, wherein the index information includes multiple file numbers and a first position parameter, the multiple file numbers correspond to multiple storage spaces one by one, the first position parameter is used to represent the file number corresponding to the first storage space written most recently, and the first storage space is one of the multiple storage spaces; obtain the first data amount of the data currently stored in the first storage space corresponding to the first position parameter; when the first data amount is equal to the first threshold, use the next position parameter adjacent to the first position parameter as the first target position, wherein the first threshold is used to represent the maximum storage capacity corresponding to the first storage space; write the data to be written to the target storage space corresponding to the first target position, and update the first position parameter in the index information to the first target position. The data stored in the storage space can be regarded as historical data. If the time length for storing historical data is set, the corresponding historical data will be deleted after the time length is exceeded, which may cause more historical data to be deleted. In the present application, data is stored in multiple storage spaces. When the first data amount of data currently stored in the first storage space is equal to a first threshold, the data to be written can be written to the target storage space corresponding to the first target location, which will only affect the historical data stored in the target storage space, but will not affect the historical data stored in the storage space outside the target storage space, so that as much historical data as possible can be retained.
[0016] Other features and advantages of the embodiments of the present application will be described in the subsequent description, and partly become apparent from the description, or can be understood by practicing the embodiments of the present application. The purposes and other advantages of the embodiments of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0018] Figure 1 A method flow chart of a data storage method provided by an embodiment of the present application is shown;
[0019] Figure 2 A method flow chart of a data storage method provided by another embodiment of the present application is shown;
[0020] Figure 3 It shows a structural block diagram of the physical space provided by the present application;
[0021] Figure 4 A method flow chart of a data storage method provided by another embodiment of the present application is shown;
[0022] Figure 5 A method flow chart of a data storage method provided by another embodiment of the present application is shown;
[0023] Figure 6 A method flow chart of a data storage method provided by another embodiment of the present application is shown;
[0024] Figure 7 A method flow chart of a data storage method provided by another embodiment of the present application is shown;
[0025] Figure 8 A structural block diagram of a data storage device provided in an embodiment of the present application is shown;
[0026] Fig. 9 A structural block diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0027] In order to make those skilled in the art better understand the present application scheme, the technical scheme in the present application embodiment will be clearly and completely described below in conjunction with the drawings in the present application embodiment. Obviously, the described embodiment is only a part of the present application embodiment, rather than all the embodiments. The components of the present application embodiment usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the present application for protection, but merely represents the selected embodiment of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0028] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0029] At present, with the development of electronic information technology, data can be stored in the storage space of a storage medium. Although the data stored in the storage space can be deleted, so as to use the storage space to store new data. However, the current method of deleting the stored data and storing new data may cause a lot of stored data to be deleted. How to save as much stored data as possible is a problem to be solved urgently.
[0030] At present, electronic devices can run applications, and data will be generated during the running of applications. The generated data can be stored in a storage medium, and the stored data can be regarded as historical data. For example, the storage medium may include a disk, a flash memory (FLASH) or an electrically erasable programmable read-only memory (Electrically Erasable ProgrammableRead-Only Memory, EEPROM), etc. It is understandable that the capacity of the storage medium is limited to a certain extent, and historical data cannot generally be stored permanently. Therefore, it can be set to store historical data for a recent period of time, such as storing historical data for one month, and historical data older than one month can be deleted.
[0031] However, the inventors have found in their research that the method of storing historical data of the most recent period may cause a lot of historical data to be deleted.
[0032] Therefore, in order to solve or partially solve the above problems, the present application provides a data storage method, device and electronic device.
[0033] See also Figure 1 , Figure 1 A method flow chart of a data storage method provided by an embodiment of the present application is shown. The data storage method can be applied to an electronic device, and specifically, a processor of the electronic device can be used as an execution subject of the data storage method. The data storage method specifically includes steps S110 to S140.
[0034] Step S110: In response to a file write request, obtain the data to be written and index information, wherein the index information includes multiple file numbers and a first position parameter, the multiple file numbers correspond one-to-one to the multiple storage spaces, the first position parameter is used to represent the file number corresponding to the first storage space that was most recently written, and the first storage space is one of the multiple storage spaces.
[0035] In the embodiments provided in the present application, the file write request may be request information obtained by the electronic device, and the file write request may be generated by an application running on the electronic device, for example, a user generates a file write request by operating an application running on the electronic device; the file write request may also be sent to the electronic device by other devices that have established a communication connection with the electronic device, for example, a user generates a file write request through other devices and then sends the file write request to the electronic device. Among them, the other device may be a cloud server, etc.
[0036] It is understood that the electronic device may generally be provided with a storage medium, so that data may be written into the storage medium to store the data in the storage medium, and data stored in the storage medium may also be read to read the data. In some embodiments, the stored data may be referred to as historical data.
[0037] When the storage medium is full of data and needs to store new data, the historical data in the storage medium can be deleted to release the capacity of the storage medium so that the storage medium can store new data. However, if the historical data in the entire storage medium is directly deleted, more historical data will be deleted, making it impossible to retain more historical data through the storage medium, and the utilization rate of the storage medium is also low.
[0038] Therefore, the storage medium can be divided. For example, part of the physical space in the storage medium can be divided into multiple storage spaces. When multiple storage spaces are already full of historical data and new data needs to be written, the historical data stored in only one storage space can be deleted, and the new data can be written to the storage space where the historical data has been deleted, while the historical data in other storage spaces can be retained. In this way, more historical data can be retained without affecting the writing of new data, and a large amount of idle capacity of the storage medium can be avoided, thereby improving the utilization rate of the storage medium.
[0039] The storage medium may be an embedded multimedia memory card (EMMC). Thus, the stability of data reading and writing can be improved and the probability of storage medium damage can be reduced through the inherent read and write error correction capability of the embedded multimedia memory card.
[0040] It is understandable that, in order to facilitate the location of the storage space, in some embodiments, index information corresponding to the storage medium may also be constructed, and the index information may include multiple file numbers, wherein the multiple file numbers correspond one-to-one to the multiple storage spaces. In other words, if there are N file numbers, there may be N storage spaces, and the multiple file numbers correspond one-to-one to the multiple storage spaces. Exemplarily, file number 0 corresponds to storage space 0, file number 1 corresponds to storage space 1, file number 2 corresponds to storage space 2, and so on.
[0041] Each storage space may be used to perform a cyclic write operation based on a data write sequence, that is, data may be cyclically written into each storage space in sequence based on the data write sequence.
[0042] Thus, the electronic device can obtain the data to be written and the index information in response to the file write request. For some embodiments, the index information can be stored in the electronic device, for example, in the form of an index file. Thus, after the electronic device obtains the file write request, it can search for the index information in the stored index file. The data to be written can be the data corresponding to the file write request, and the data to be written is the data to be stored. Exemplarily, the data to be written can be packet data.
[0043] Optionally, each storage space may be further divided into a plurality of packet data spaces, and each packet data space may be used to store one packet data. Exemplarily, one packet data may be 56 kB in size, and one packet data space may have a capacity of 56 kB.
[0044] In addition, each packet data space in the storage space may also correspond to a sequence number, namely, a packet data space sequence number. The packet data space sequence number may also be stored in the index information. Exemplarily, packet data space sequence number 0 corresponds to packet data space 0, packet data space sequence number 1 corresponds to packet data space 1, and packet data space sequence number 2 corresponds to packet data space 2. Thus, when data is subsequently read, the packet data space may be located in combination with the file sequence number and the packet data space sequence number, thereby obtaining the stored data.
[0045] Therefore, data can be written or read from each storage space in the storage medium based on the index information, without having to traverse each storage space in the storage medium each time data is written or read, thereby improving data access efficiency to a certain extent.
[0046] In addition, in order to write data to the storage space, the index information may also include a first position parameter. The first position parameter is used to represent the file sequence number corresponding to the first storage space that was written most recently, for example, the file sequence number corresponding to the storage space written by the last file write request adjacent to the current file write request. In some embodiments, the first position parameter may be represented by W_N. As can be seen from the above introduction, each file sequence number may correspond to a storage space, so that the first storage space may be one of the multiple storage spaces.
[0047] For some embodiments, data can be stored based on a file system. Among them, the file system can be a system responsible for managing data in a storage medium, and can provide a set of abstract layers so that users and applications can access data stored on a storage medium in a unified and efficient manner. Exemplarily, the file system can be a file allocation table (FileAllocation Table, FAT), a Linux extended file system (Extended File System, Extfs) or a YAFFS file system (Yet Another Flash File System, YAFFS), etc., wherein the Linux extended file system can also include the third generation (Ext3) and the fourth generation (Ext4). Thus, due to the use of a file system, the data storage method provided in the embodiment of the present application can be easily transplanted to other operating systems.
[0048] Step S120: Acquire a first data volume of data currently stored in a first storage space corresponding to the first position parameter.
[0049] The first position parameter may correspond to the first storage space, and the first storage space may be full of data. Therefore, before writing the data to be written into the first storage space, the first data volume of the data currently stored in the first storage space corresponding to the first position parameter may be first obtained. Thus, it is determined whether the first storage space is full of data based on the first data volume. The storage space corresponding to the file number represented by the first position parameter can be used as the first storage space.
[0050] The electronic device may directly query the first data volume of the data currently stored in the first storage space, for example, through an operating system.
[0051] Step S130: when the first data volume is equal to a first threshold, taking a next position parameter adjacent to the first position parameter as a first target position, wherein the first threshold is used to represent a maximum storage capacity corresponding to the first storage space.
[0052] For some implementations, the first data amount can be compared with the first threshold to determine whether the first storage space is full of data. The first threshold is used to represent the maximum storage capacity corresponding to the first storage space. Thus, when the first storage space is equal to the first threshold, it can be determined that the first storage space is full of data; and when the first storage space is less than the first threshold, it can be determined that the first storage space is not yet full of data. In some implementations, the first threshold can be represented by S_THRESHHOLD.
[0053] Furthermore, when the first storage space is full of data, that is, when the first data amount is equal to the first threshold, the next position parameter adjacent to the first position parameter may be used as the first target position.
[0054] It should be noted that, since the first position parameter is one of the file numbers, the next position parameter adjacent to the first position parameter may be the next file number adjacent to the file number corresponding to the first position parameter. For example, if the first position parameter is file number 1, the first target position may be file number 2.
[0055] Step S140: writing the data to be written into the target storage space corresponding to the first target position, and updating the first position parameter in the index information to the first target position.
[0056] Thus, the data to be written can be written into the target storage space corresponding to the first target location. It is understandable that the target storage space may already have stored data, that is, historical data. Therefore, in some embodiments, the target storage space can be directly overwritten, that is, the data to be written can be written into the target storage space in an overwritten manner; for other embodiments, the data stored in the target storage space can be deleted, and then the data to be written can be written into the target storage space.
[0057] Furthermore, since the current writing position is changed to the first target position, the first position parameter in the index information may also be updated to the first target position.
[0058] It is understandable that, since each storage space performs a cyclic write operation based on the data write order, the storage duration of the data stored in the target storage space corresponding to the first target position is longer than the storage duration of the data stored in the storage space outside the target storage space. Among them, the storage duration is the duration between the moment when the data is stored in the storage space and the current moment. Therefore, in the embodiment of the present application, writing the data to be written to the target storage space can retain some historical data closer to the current moment to a large extent, that is, the data to be deleted or overwritten is the data with the longest storage duration in all storage spaces.
[0059] When the first data volume is less than the first threshold, it indicates that data can still be stored in the first storage space at this time, so the data to be written can be written into the first storage space. In addition, since the first storage space is not full of data at this time, the data to be written is written into the first storage space, and there is no need to delete or overwrite the historical data stored in the first storage space, so as to retain as much historical data as possible.
[0060] The data storage method provided by the embodiment of the present application first responds to a file write request, obtains the data to be written and index information, wherein the index information includes multiple file numbers and a first position parameter, the multiple file numbers correspond to multiple storage spaces one by one, the first position parameter is used to represent the file number corresponding to the first storage space written most recently, and the first storage space is one of the multiple storage spaces; obtains the first data amount of the data currently stored in the first storage space corresponding to the first position parameter; when the first data amount is equal to the first threshold, the next position parameter adjacent to the first position parameter is used as the first target position, wherein the first threshold is used to represent the maximum storage capacity corresponding to the first storage space; writes the data to be written to the target storage space corresponding to the first target position, and updates the first position parameter in the index information to the first target position. The data stored in the storage space can be regarded as historical data. If the time length for storing historical data is set, the corresponding historical data will be deleted after the time length is exceeded, which may cause more historical data to be deleted. In the present application, data is stored in multiple storage spaces. When the first data amount of data currently stored in the first storage space is equal to a first threshold, the data to be written can be written to the target storage space corresponding to the first target location, which will only affect the historical data stored in the target storage space, but will not affect the historical data stored in the storage space outside the target storage space, so that as much historical data as possible can be retained.
[0061] See also Figure 2 , Figure 2A method flow chart of a data storage method provided by an embodiment of the present application is shown. The data storage method can be applied to an electronic device, and specifically, a processor of the electronic device can be used as the execution subject of the data storage method. The data storage method specifically includes steps S210 to S290.
[0062] Step S210: In response to a file write request, obtain the data to be written and index information, wherein the index information includes multiple file numbers and a first position parameter, the multiple file numbers correspond one-to-one to the multiple storage spaces, the first position parameter is used to represent the file number corresponding to the first storage space most recently written, and the first storage space is one of the multiple storage spaces.
[0063] Step S220: Obtain a first data volume of data currently stored in a first storage space corresponding to the first position parameter.
[0064] Among them, step S210 and step S220 have been introduced in detail in the above embodiments and will not be repeated here.
[0065] Step S230: when the first data amount is equal to a first threshold, add 1 to the first position parameter to obtain a first value.
[0066] Step S240: taking the remainder after dividing the first value by a second threshold as the first target position, wherein the second threshold is the amount of storage space.
[0067] For some implementations, when the first data volume is equal to the first threshold value, the first target position can be determined by taking a modulus. Specifically, the first position parameter can be added by 1 to obtain the first value. Then, the first value is divided by the second threshold value, and the remainder after the division is used as the first target position. Wherein, the second threshold value is the number of storage spaces. Exemplarily, part of the physical space in the storage medium can be divided into 100 storage spaces, and the second threshold value is 100. Take the first position parameter to represent the file number 90 as an example for introduction. The first value obtained after the first position parameter is added by 1 is 91, so the remainder after 91 is divided by 100 is 91, and the file number 91 can be used as the first target position. Another exemplary example is to take the first position parameter to represent the file number 99 as an example for introduction. The first value obtained after the first position parameter is added by 1 is 100, so the remainder after 100 is divided by 100 is 0, and the file number 0 can be used as the first target position. Taking the storage space as 100 as an example, the corresponding file numbers are 0 to 99, where file number 0 is the starting file number and file number 99 is the last file number. It can be seen that the next file number adjacent to the last file number is the starting file number, thus realizing cyclic writing.
[0068] In some embodiments, the second threshold value may be represented as DFILE_MAXS, and the first target position may be represented as N_WRI TE. Thus, the first value may be represented as (W_N+1), and N_WRI TE=(W_N+1)%DFI LE_MAXS.
[0069] In addition, the total data size that can be stored in multiple storage spaces can be determined by multiplying the first threshold by the second threshold. Specifically, the total data size can be represented by MAX_STORAGE_SIZE=S_THRESHHOLD*DFILE_MAXS. Therefore, the first threshold can also be set by the total data size, for example, the first threshold is set to 1% of the total data size.
[0070] For example, see Figure 3 , Figure 3 A structural block diagram of the physical space provided in an embodiment of the present application is shown. Figure 3 The physical space 300 shown is divided into 100 storage spaces, each of which is represented by 0.db, 1.db, ..., to 99.db. Figure 3 In the physical space 300 shown in FIG. 1 , the first threshold corresponding to each storage space is 3 MB, so that the total data size of the physical space is 300 MB. In addition, Figure 3 The figure also shows a first index file 310 and a second index file 320 corresponding to the physical space 300. The second index file 320 is a backup file of the first index file 310. The first index file 310, the second index file 320 and the physical space 300 are all included in the storage medium 390, and the first index file 310, the second index file 320 and the physical space 300 are connected to each other.
[0071] It is understandable that the maximum storage capacity of the storage space can be adjusted to flexibly adjust the specific amount of historical data stored in the target storage space for deletion.
[0072] Furthermore, in the embodiment of the present application, data writing with almost unlimited capacity is achieved in a relatively limited physical space through cyclic writing. Moreover, the effect of write balance can also be achieved through cyclic writing. Among them, it can be understood that the physical space is generally composed of multiple storage units, and write balance means that data will be written to each storage unit in the physical space more evenly, rather than only writing data to a small number of storage units, thereby avoiding the long-term use of a small number of storage units for data writing and accelerating the damage of a small number of storage units, thereby improving the service life of the storage medium.
[0073] Step S250: writing the data to be written into the target storage space corresponding to the first target position, and updating the first position parameter in the index information to the first target position.
[0074] Among them, step S250 has been introduced in detail in the above embodiment and will not be repeated here.
[0075] Step S260: In response to the data read request, determine a second storage space corresponding to the second location parameter.
[0076] Step S270: Determine the designated packet data space corresponding to the designated packet data space sequence number in the second storage space.
[0077] Step S280: Read the data stored in the designated packet data space.
[0078] Furthermore, the data stored in the storage space can also be read. Specifically, the electronic device can obtain a data read request, which is similar to a file write request. The data read request can be request information obtained by the electronic device. The data read request can be generated by an application running on the electronic device, for example, a user generates a data read request by operating an application running on the electronic device; the data read request can also be sent to the electronic device by other devices that have established a communication connection with the electronic device, for example, a user generates a data read request through other devices and then sends the data read request to the electronic device.
[0079] In some embodiments, each storage space can be divided into multiple packet data spaces, so that the index information can also include a second position parameter and a designated packet data space sequence number, and then the packet data space that needs to read data can be located based on the second position parameter and the designated packet data space sequence number. Among them, similar to the first position parameter, the second position parameter is used to represent the file sequence number corresponding to the second storage space read most recently, such as the file sequence number corresponding to the storage space read by the last data read request adjacent to the current data read request. In some embodiments, the second position parameter can be represented as R_N, and the designated packet data space sequence number can be represented as R_ID.
[0080] It should be noted that the multiple packet data spaces in each storage space may correspond to packet data space serial numbers, so that the designated packet data space serial number represents the currently read packet data space serial number.
[0081] After responding to the data read request, the second position parameter and the designated packet data space sequence number may be further acquired according to the acquired index information.
[0082] Therefore, the second storage space corresponding to the second position parameter can be determined, that is, the storage space corresponding to the file number represented by the second position parameter can be used as the second storage space.
[0083] It can be understood that the second storage space may include multiple packet data spaces, and which packet data space in the second storage space needs to be read specifically can be determined in combination with the designated packet data space sequence number.
[0084] Therefore, the designated packet data space corresponding to the designated packet data space sequence number can be determined in the second storage space. Exemplarily, if the second storage space includes 10 packet data spaces, the packet data space sequence numbers can be 0 to 9. If the designated packet data space sequence number is 0, the first packet data space can be determined in the second storage space as the designated packet data space. It should be noted that the above is only an introduction to the designated packet data space and does not constitute a limitation on the embodiments of the present application.
[0085] Thus, the data stored in the designated packet data space can be read, and the data stored in the designated packet data space is also the data to be read in response to the data read request.
[0086] Step S290: Update the designated packet data space sequence number in the index information to the next packet data space sequence number adjacent to the designated packet data space sequence number.
[0087] Furthermore, in order to be able to sequentially read the data stored in the next packet data space adjacent to the designated packet data space when receiving the next data read request, the designated packet data space sequence number in the index information may be updated to the next packet data space sequence number adjacent to the designated packet data space sequence number. In some implementations, the next packet data space sequence number adjacent to the designated packet data space sequence number may be represented by READ_ID, specifically, READ_ID=R_ID+1.
[0088] Optionally, for some implementations, if the designated packet data space sequence number is already the last packet data space in the second storage space, the second position parameter in the index information may also be updated. Specifically, step S290 may also include step S291 and step S292.
[0089] Step S291: when the designated packet data space sequence number is a third threshold, the next position parameter adjacent to the second position parameter is used as the second target position, wherein the third threshold is the maximum value of the packet data space sequence number corresponding to the packet data space in the second storage space.
[0090] Step S292: Update the second position parameter in the index information to the second target position, and update the designated packet data space number in the index information to the initial address.
[0091] Among them, the third threshold is the maximum value of the packet data space sequence number corresponding to the packet data space in the second storage space. Exemplarily, the third threshold can be determined based on the number of packet data spaces in the second storage space. For example, if the packet data space sequence number in the second storage space is 0 as the starting address, the number of packet data spaces in the second storage space minus 1 can be used as the third threshold; if the packet data space sequence number in the second storage space is 1 as the starting address, the number of packet data spaces in the second storage space can be used as the third threshold. For example, if the number of packet data spaces in the second storage space is 100, and the packet data space sequence number in the second storage space is from 0 to 99, the third threshold can be determined as 99; if the packet data space sequence number in the second storage space is from 1 to 100, the third threshold can be determined as 100. It should be noted that the above-mentioned third thresholds are only an example description and are not intended to be a limitation on the embodiments of the present application.
[0092] Thus, when the designated packet data space sequence number is the third threshold, it indicates that the packet data space corresponding to the designated packet data space sequence number is already the packet data space at the end of the sorting in the second storage space. Thus, at this time, the next position parameter adjacent to the second position parameter can be used as the second target position. That is to say, when a data read request is detected later, data can be read from the storage space corresponding to the next position parameter adjacent to the second position parameter. In some embodiments, the second target position can be represented as READ_N.
[0093] Specifically, the second position parameter in the index information may be updated to the second target position, and the designated packet data space number in the index information may be updated to the initial address. Thus, when responding to a data read request again later, the designated packet data space number in the index information is the updated initial address, and the second position parameter is the updated second target position.
[0094] The initial address may be used to indicate the starting position of the packet data space sequence number, such as the packet data space sequence number 0. Thus, READ_ID=0.
[0095] In addition, when the designated packet data space sequence number is not the third threshold value, it indicates that the packet data space corresponding to the designated packet data space sequence number is not the packet data space at the end of the sort in the second storage space, so that the designated packet data space sequence number in the index information can be directly updated to the next packet data space sequence number adjacent to the designated packet data space sequence number.
[0096] Among them, step S292 can also include step S2921 and step S2922.
[0097] Step S2921: when the designated packet data sequence number is the third threshold, the second position parameter is increased by 1 to obtain a second value.
[0098] Step S2922: taking the remainder after dividing the second value by a second threshold as the second target position, wherein the second threshold is the amount of storage space.
[0099] In some embodiments, when the designated packet data sequence number is the third threshold, the second position parameter can be added by 1 to obtain a second value. Then the remainder after the second value is divided by the second threshold is used as the second target position, wherein the second threshold is the number of storage spaces. Exemplarily, if part of the physical space in the storage medium is divided into 100 storage spaces, the second threshold is 100. Taking the second position parameter representing the file sequence number 90 as an example, the second value obtained after the second position parameter is added by 1 is 91, so the remainder after 91 is divided by 100 is 91, and the file sequence number 91 can be used as the second target position. Another exemplary example is to take the second position parameter representing the file sequence number 99 as an example, the second value obtained after the second position parameter is added by 1 is 100, so the remainder after 100 is divided by 100 is 0, and the file sequence number 0 can be used as the second target position. Taking the storage space as 100 as an example, the corresponding file sequence numbers are 0 to 99, wherein the file sequence number 0 is the starting file sequence number, and the file sequence number 99 is the last file sequence number. It can be seen that the next file number adjacent to the last file number is the starting file number, thereby realizing cyclic reading.
[0100] Therefore, the second value may be (R_N+1), and READ_N=(R_N+1)%DFILE_MAXS.
[0101] The data storage method provided by the embodiment of the present application, when the first data amount is equal to the first threshold value, the first position parameter is added by 1 to obtain the first value; the remainder after dividing the first value by the second threshold value is used as the first target position, wherein the second threshold value is the number of storage spaces. Among them, the next file sequence number adjacent to the last file sequence number is the starting file sequence number, thereby realizing cyclic writing. In addition, the embodiment of the present application can also determine the second storage space corresponding to the second position parameter in response to a data read request; determine the designated package data space corresponding to the designated package data space sequence number in the second storage space; read the data stored in the designated package data space; update the designated package data space sequence number in the index information to the next package data space sequence number adjacent to the designated package data space sequence number. Among them, the next file sequence number adjacent to the last file sequence number is the starting file sequence number, thereby realizing cyclic reading.
[0102] See also Figure 4 , Figure 4 A method flow chart of a data storage method provided by an embodiment of the present application is shown. The data storage method can be applied to an electronic device, and specifically, a processor of the electronic device can be used as an execution subject of the data storage method. The data storage method specifically includes steps S310 to S360.
[0103] Step S310: sequentially determining a file write request from a write request sequence as a target file write request, wherein the write request sequence includes a plurality of file write requests.
[0104] Step S320: In response to the target file write request, obtain the data to be written and the index information.
[0105] In some implementations, a write request sequence may be obtained, wherein the write request sequence includes multiple file write requests. Thus, a file write request may be determined in sequence as a target file write request, and then the target file write request may be executed in response to obtain the data to be written and the index information.
[0106] The acquired data to be written is the data to be written corresponding to the target write request.
[0107] In some implementations, the acquired initial data set may be segmented to construct a write request sequence. Specifically, step S310 may further include steps S311 to S313.
[0108] Step S311: Acquire an initial data set.
[0109] Step S312: Divide the initial data set based on a fourth threshold to obtain multiple data to be written and the arrangement order of each data to be written, each data to be written corresponds to a file write request, wherein the fourth threshold is used to characterize the storage capacity of each packet data space in the storage space.
[0110] Step S313: Arrange the multiple file write requests in the order of arrangement of the to-be-written data corresponding to each file write request to obtain the write request sequence.
[0111] The initial data set may be a data set consisting of data to be written, which may include multiple data or only one data, which is not specifically limited in the embodiments of the present application. As can be seen from the foregoing introduction, the storage space may be divided into multiple package data spaces. If the second data volume of the initial data set is large, for example, the second data volume is greater than the storage capacity of each package data space, an error may occur in the process of writing the data to be written.
[0112] Therefore, in order to improve the stability of subsequent writing of the data to be written, the initial data set can be first divided based on the fourth threshold to obtain multiple data to be written and the arrangement order of each data to be written, each of the data to be written corresponds to a file write request, wherein the fourth threshold is used to characterize the storage capacity of each package data space in the storage space.
[0113] Exemplarily, the fourth threshold may be used as the size of each data to be written after segmentation to segment the initial data set. For example, if the fourth threshold is 56 kB, multiple data to be written after segmentation may be obtained, wherein each data to be written is 56 kB.
[0114] Among the obtained multiple data to be written, each data to be written may correspond to a file write request. Moreover, the obtained multiple data to be written have an arrangement order. Thus, the multiple file write requests may be arranged in the arrangement order of the data to be written corresponding to each file write request, so as to construct a write request sequence. Subsequently, a file write request in the write request sequence may be sequentially used as a target file write request.
[0115] Step S330: Obtain a first data volume of data currently stored in a first storage space corresponding to the first position parameter.
[0116] Step S340: when the first data volume is equal to a first threshold, taking the next position parameter adjacent to the first position parameter as the first target position, wherein the first threshold is used to represent the maximum storage capacity corresponding to the first storage space.
[0117] Step S350: writing the data to be written into the target storage space corresponding to the first target position, and updating the first position parameter in the index information to the first target position.
[0118] Among them, step S330 to step S350 have been introduced in detail in the above embodiments and will not be repeated here.
[0119] Step S360: Return to execute the step of sequentially determining a file write request from the write request sequence as the target file write request and subsequent steps until each file write request in the write request sequence is used as the target file write request.
[0120] After executing step S350, the process may return to executing the process of sequentially determining a file write request from the write request sequence as the target file write request and subsequent steps until each file write request in the write request sequence is used as the target file write request.
[0121] Exemplarily, if the write request sequence includes three file write requests, namely the first file write request, the second file write request and the third file write request. Then, the first file write request can be used as the target file write request to execute steps S320 to S360, and then the process returns to step S310 to use the second file write request as the target file write request to execute steps S320 to S360, and then the process returns to step S310 again to use the third file write request as the target file write request to execute steps S320 to S360. At this time, if it is detected that each file write request in the write request sequence is used as the target file write request, it can be determined that the data storage method provided in the embodiment of the present application has been executed.
[0122] The data storage method provided by the embodiment of the present application sequentially determines a file write request from a write request sequence as a target file write request, wherein the write request sequence includes multiple file write requests; in response to the target file write request, obtains the data to be written and the index information; after the data to be written is written into the target storage space corresponding to the first target position and the first position parameter in the index information is updated to the first target position, it also includes: returning to execute sequentially determining a file write request from the write request sequence as the target file write request and subsequent steps until each file write request in the write request sequence is used as the target file write request. In addition, by obtaining an initial data set, the initial data set is segmented based on a fourth threshold to obtain multiple data to be written and the arrangement order of each data to be written, each of the data to be written corresponds to a file write request, wherein the fourth threshold is used to characterize the storage capacity of each packet data space in the storage space; multiple file write requests are arranged in the arrangement order of the data to be written corresponding to each file write request, and the write request sequence is constructed. Thus, by segmenting the initial data set so that the size of each data to be written is the fourth threshold, the stability of subsequent writing of the data to be written is improved.
[0123] See also Figure 5 , Figure 5 A method flow chart of a data storage method provided by an embodiment of the present application is shown. The data storage method can be applied to an electronic device, and specifically, a processor of the electronic device can be used as an execution subject of the data storage method. The data storage method specifically includes steps S410 to S470.
[0124] Step S410: In response to a file write request, obtain data to be written.
[0125] Step S420: Acquire the index information from the first index file.
[0126] Step S430: if the index information is not successfully obtained from the first index file, the index information is obtained from a second index file, wherein the second index file is a backup file of the first index file.
[0127] For the relevant introduction of obtaining the data to be written in response to the file write request, please refer to the aforementioned embodiment, which will not be repeated here.
[0128] It is understandable that since index information is a file that is read and written at a relatively high frequency, in order to prevent unexpected situations from causing abnormalities in the index information, such as sudden power outages in electronic devices or system abnormalities, it is also possible to increase the redundancy of the index information by setting up backup index information, thereby ensuring that the index information can be obtained and updated normally.
[0129] Specifically, the index information may be first obtained from the first index file, and if the index information cannot be obtained from the first index file, the index information may be further obtained from the second index file, wherein the second index file is a backup file of the first index file.
[0130] It is understandable that each time the index information is updated, the first index file and the second index file are actually updated at the same time, thereby ensuring that the first index file and the second index file are updated synchronously.
[0131] Step S440: Obtain a first data volume of data currently stored in a first storage space corresponding to the first position parameter.
[0132] Step S450: when the first data volume is equal to a first threshold, taking the next position parameter adjacent to the first position parameter as the first target position, wherein the first threshold is used to represent the maximum storage capacity corresponding to the first storage space.
[0133] Among them, step S440 and step S450 have been introduced in detail in the above embodiments and will not be repeated here.
[0134] Step S460: deleting the data stored in the target storage space corresponding to the first target location.
[0135] Step S470: writing the data to be written into the target storage space corresponding to the first target position, and updating the first position parameter in the index information to the first target position.
[0136] In some implementations, the target storage space may already have data stored, that is, the data stored in the target storage space is historical data, and in this case, the data stored in the target storage space corresponding to the first target location may be deleted first. Then, the data to be written is written to the target storage space corresponding to the first target location, and the first location parameter in the index information is updated to the first target location. For a detailed description, please refer to the aforementioned embodiment, which will not be repeated here.
[0137] The data storage method provided in the embodiment of the present application improves the redundancy of index information by setting backup index information. In addition, only the historical data stored in the target storage space needs to be deleted, without affecting the historical data stored in the storage space outside the target storage space, so that more historical data can be retained. Furthermore, in the data storage method provided in the embodiment of the present application, the maximum storage capacity of the storage space can be adjusted, so that the specific amount of historical data stored in the target storage space can be flexibly adjusted as needed.
[0138] See also Figure 6 , Figure 6 A method flow chart of a data storage method provided by an embodiment of the present application is shown. The data storage method can be applied to an electronic device, and specifically, a processor of the electronic device can be used as an execution subject of the data storage method. The data storage method specifically includes steps S510 to S5110.
[0139] Step S510: In response to a file write request, obtain data to be written and index information.
[0140] The relevant introduction of step S510 can be found in the aforementioned embodiment and will not be repeated here.
[0141] Step S520: Obtain a first position parameter.
[0142] The first position parameter may be represented by W_N. The index information may include multiple file numbers and the first position parameter, the first position parameter is one of the multiple file numbers, the first position parameter is used to represent the most recent write position, each file number corresponds to a storage space, and each storage space performs a cyclic write operation based on the data write order. Therefore, the first position parameter can be obtained through the index information.
[0143] Step S530: Whether the first data is equal to the first threshold.
[0144] Further, it can be determined whether the first data is equal to a first threshold, wherein the first data is the amount of data currently stored in the first storage space corresponding to the first position parameter, and the first threshold is used to characterize the maximum storage capacity corresponding to the first storage space. Thus, if the first data is equal to the first threshold, the execution can be jumped to step S540; if the first data is not equal to the first threshold, the execution can be jumped to step S550.
[0145] It should be noted that, since the first threshold represents the maximum storage capacity corresponding to the first storage space, the first data is generally not greater than the first threshold. Therefore, if the first data is not equal to the first threshold, it represents that the first data is less than the first threshold.
[0146] Step S540: when the first data amount is equal to the first threshold, writing the data to be written into the target storage space.
[0147] Step S550: when the first data amount is not equal to the first threshold, writing the data to be written into the first storage space.
[0148] When the first data volume is equal to the first threshold, the data to be written may be written into the target storage space, wherein the target storage space is the storage space corresponding to the first target position, and the first target position is the next position parameter adjacent to the first position parameter.
[0149] When the first data amount is not equal to the first threshold, the data to be written may be written into the first storage space.
[0150] For a detailed introduction, please refer to the description of the aforementioned embodiment, which will not be repeated here.
[0151] Step S560: Whether the writing is successful.
[0152] For some embodiments, it is also possible to detect whether the data to be written is successfully written. Exemplarily, if the poem to be written is successfully written, a first identification information can be generated, and if the data to be written is not successfully written, a second identification information can be generated. The first identification information is used to indicate that the data to be written has been successfully written, and the second identification information is used to indicate that the data to be written is not successfully written. Thus, the electronic device can determine whether the data to be written is successfully written based on the first identification information or the second identification information obtained.
[0153] It should be noted that whether the data to be written is successfully written specifically refers to whether it is successfully written into the target storage space when the first data volume is equal to the first threshold; whether it is written into the first storage space when the first data volume is not equal to the first threshold.
[0154] Therefore, when successful writing is detected, the execution can jump to step S5110; and when unsuccessful writing is detected, the execution can jump to step S570.
[0155] Step S570: If the writing is unsuccessful, the number of times the current data to be written has been written is detected.
[0156] Step S580: Check whether the number of times the current data to be written has been written exceeds the specified number of times.
[0157] Step S590: If not exceeded, return to execute step S530.
[0158] Step S5100: If exceeded, the storage space currently being written is deleted, and the response to the current file write request ends.
[0159] In the case of detecting that the writing is unsuccessful, the number of times the current data to be written has been written can be further detected, and then whether it is necessary to write again can be determined based on the number of times the current data to be written has been written. Specifically, it can be determined whether the number of times the current data to be written has been written exceeds a specified number of times. If it exceeds the specified number of times, the execution can be jumped to step S5100; if it does not exceed the specified number of times, the execution can be jumped to step S590.
[0160] When it is detected that the specified number of times has not been exceeded, the process may return to step S530 to write the data to be written again.
[0161] When it is detected that the number of times exceeds the specified number, the storage space currently being written can be deleted, and the response to the current file writing request ends, thereby preventing the data storage method from falling into an endless loop and improving the stability of the data storage method.
[0162] Step S5110: If the writing is successful, the first position parameter in the index information is updated.
[0163] If successful writing is detected, the first position parameter in the index information can be updated. Specifically, when the first data volume is equal to the first threshold, the first position parameter in the index information is updated to the first target position; when the first data volume is not equal to the first threshold, the first position parameter in the index information remains unchanged.
[0164] For detailed description of each step in the embodiments of the present application, please refer to the description in the aforementioned embodiments, which will not be repeated here.
[0165] See also Figure 7 , Figure 7 A method flow chart of a data storage method provided by an embodiment of the present application is shown. The data storage method can be applied to an electronic device, and specifically, a processor of the electronic device can be used as an execution subject of the data storage method. The data storage method specifically includes steps S610 to S690.
[0166] Step S610: responding to a data read request.
[0167] In some implementations, in response to the data read request, subsequent steps of reading data may be triggered.
[0168] Step S620: Acquire the index information from the first index file.
[0169] Step S630: Whether the index information is successfully obtained from the first index file.
[0170] First, the index information can be obtained from the first index file. It is determined whether the index information is successfully obtained from the first index file. If the index information is not successfully obtained from the first index file, the process can jump to step S640; if the index information is successfully obtained from the first index file, the process can jump to step S650.
[0171] Step S640: if the index information is not successfully obtained from the first index file, the index information is obtained from a second index file, wherein the second index file is a backup file of the first index file.
[0172] In the case where the index information is not successfully acquired from the first index file, the index information may be further acquired from a second index file, wherein the second index file is a backup file of the first index file.
[0173] In some implementation modes, the first index file may be regarded as a primary index file, and the second index file may be regarded as a backup index file of the primary index file.
[0174] Therefore, by setting up a method of backing up index information, the redundancy of index information can be improved.
[0175] It should be noted that, in the aforementioned embodiment, in response to a file write request, index information may also be obtained through the method provided in the aforementioned steps S620 to S640.
[0176] Step S650: Obtain a second position parameter and a designated packet data space sequence number from the index information.
[0177] Step S660: Read the data stored in the designated packet data space.
[0178] Since the index information may also include a second position parameter and a designated packet data space sequence number, after the index information is obtained, the second position parameter and the designated packet data space sequence number may be obtained from the index information. The second position parameter is one of the plurality of file sequence numbers, and the second position parameter is used to represent the most recent read position. The plurality of packet data spaces in each storage space may correspond to packet data space sequence numbers, so that the designated packet data space sequence number represents the currently read packet data space sequence number.
[0179] Furthermore, the data stored in the designated packet data space can be read. The designated packet data space is the packet data space corresponding to the packet data space sequence number. Specifically, the second storage space corresponding to the second position parameter can be first determined; and then the designated packet data space corresponding to the designated packet data space sequence number can be determined in the second storage space.
[0180] Step S670: Determine whether the packet data space sequence number is a third threshold.
[0181] It can be further determined whether the designated packet data space sequence number is a third threshold value, wherein the third threshold value is the maximum value of the packet data space sequence number corresponding to the packet data space in the second storage space. If it is determined that the designated packet data space sequence number is the third threshold value, the process can jump to step S680; and if it is determined that the designated packet data space sequence number is not the third threshold value, the process can jump to step S690.
[0182] Step S680: When the designated packet data space sequence number is the third threshold, the second position parameter in the index information is updated to the second target position, and the designated packet data space sequence number in the index information is updated to the initial address, and the first information is returned.
[0183] When the designated packet data space sequence number is the third threshold, it indicates that the packet data space corresponding to the designated packet data space sequence number is already the packet data space at the end of the sorting in the second storage space. Therefore, at this time, the next position parameter adjacent to the second position parameter can be used as the second target position, and then the second position parameter in the index information is updated to the second target position.
[0184] In addition, the designated packet data space number in the index information may be updated to the initial address, wherein the initial address may be used to represent the starting position of the packet data space number, such as packet data space number 0. Then, the designated packet data space number in the index information is updated to the initial address.
[0185] Optionally, the first information may be returned. The first information may be used to indicate that the second position parameter in the index information has been updated to the second target position and the designated packet data space number in the index information has been updated to the initial address. Exemplarily, the first information may be "OK".
[0186] Step S690: when the designated packet data space sequence number is not equal to the third threshold, the designated packet data space sequence number in the index information is updated to the next packet data space sequence number adjacent to the designated packet data space sequence number, and the second information is returned.
[0187] When the designated packet data space sequence number is not the third threshold, it indicates that the packet data space corresponding to the designated packet data space sequence number is not the packet data space at the end of the sorting in the second storage space, so that the designated packet data space sequence number in the index information can be directly updated to the next packet data space sequence number adjacent to the designated packet data space sequence number.
[0188] Optionally, second information may be returned, wherein the second information is used to indicate that the designated packet data space sequence number in the index information has been updated to the next packet data space sequence number adjacent to the designated packet data space sequence number. Exemplarily, the second information may be empty information.
[0189] See also Figure 8 , Figure 8 The structural block diagram of a data storage device provided by an embodiment of the present application is shown. The data storage device 800 comprises: a first acquisition unit 810 , a second acquisition unit 820 , a first target position determination unit 830 and a writing unit 840 .
[0190] A first acquisition unit 810 is used to obtain the data to be written and index information in response to a file write request, wherein the index information includes multiple file numbers and a first position parameter, the multiple file numbers correspond one-to-one to multiple storage spaces, the first position parameter is used to represent the file number corresponding to the first storage space that was most recently written, and the first storage space is one of the multiple storage spaces;.
[0191] Optionally, the first acquisition unit 810 can also be used to determine a file write request in sequence from a write request sequence as a target file write request, wherein the write request sequence includes multiple file write requests; and obtain the data to be written and index information in response to the target file write request.
[0192] Optionally, the first acquisition unit 810 can also be used to obtain the data to be written in response to a file write request; obtain the index information from the first index file; if the index information is not successfully obtained from the first index file, obtain the index information from the second index file, wherein the second index file is a backup file of the first index file.
[0193] The second acquisition unit 820 is used to acquire a first data volume of data currently stored in a first storage space corresponding to the first position parameter.
[0194] The first target position determination unit 830 is used to use the next position parameter adjacent to the first position parameter as the first target position when the first data volume is equal to a first threshold, wherein the first threshold is used to represent the maximum storage capacity corresponding to the first storage space.
[0195] Optionally, the first target position determination unit 830 can also be used to, when the first data amount is equal to a first threshold, add 1 to the first position parameter to obtain a first numerical value; and take the remainder after dividing the first numerical value by a second threshold as the first target position, wherein the second threshold is the amount of storage space.
[0196] The writing unit 840 is configured to write the data to be written into a target storage space corresponding to the first target position, and update the first position parameter in the index information to the first target position.
[0197] Optionally, the write unit 840 may also be used to return to execute the steps of sequentially determining a file write request from the write request sequence as the target file write request and subsequent steps until each file write request in the write request sequence is determined as the target file write request.
[0198] Optionally, the write unit 840 can also be used to obtain an initial data set; divide the initial data set based on a fourth threshold to obtain multiple data to be written and an arrangement order of each data to be written, each data to be written corresponds to a file write request, wherein the fourth threshold is used to characterize the storage capacity of each package data space in the storage space; arrange multiple file write requests in the arrangement order of the data to be written corresponding to each file write request to obtain the write request sequence.
[0199] Optionally, the writing unit 840 may also be configured to delete data stored in a target storage space corresponding to the first target location; and write the data to be written into the target storage space corresponding to the first target location.
[0200] The data storage device 800 further includes a reading unit ( Figure 8 (not shown), the reading unit is used to determine the second storage space corresponding to the second position parameter in response to a data read request; determine the designated packet data space corresponding to the designated packet data space sequence number in the second storage space; read the data stored in the designated packet data space; and update the designated packet data space sequence number in the index information to the next packet data space sequence number adjacent to the designated packet data space sequence number.
[0201] Optionally, the reading unit can also be used to, when the designated packet data space sequence number is a third threshold, use the next position parameter adjacent to the second position parameter as the second target position, wherein the third threshold is the maximum value of the packet data space sequence number corresponding to the packet data space in the second storage space; update the second position parameter in the index information to the second target position, and update the designated packet data space sequence number in the index information to the initial address.
[0202] Optionally, the reading unit can also be used to, when the designated packet data sequence number is a third threshold, add 1 to the second position parameter to obtain a second value; and use the remainder after dividing the second value by the second threshold as the second target position, wherein the second threshold is the amount of storage space.
[0203] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and units can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0204] In several embodiments provided in the present application, the coupling between the units may be electrical, mechanical or other forms of coupling. In addition, each functional unit in each embodiment of the present application may be integrated into a processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0205] See also Fig. 9 , Fig. 9 The block diagram of a structure of an electronic device provided in an embodiment of the present application is shown. The electronic device 110 may be a smart phone, a desktop computer, a vehicle-mounted computer, a server or a tablet computer, etc. The electronic device 110 in the present application may include one or more of the following components: a processor 111, a memory 112 and one or more application programs, wherein the processor 111 is electrically connected to the memory 112, and the one or more program configurations are used to execute the methods described in the aforementioned embodiments.
[0206] The processor 111 may include one or more processing cores. The processor 111 uses various interfaces and lines to connect various parts of the entire electronic device 110, and executes various functions and processes data of the electronic device 110 by running or executing instructions, programs, code sets or instruction sets stored in the memory 112, and calling data stored in the memory 112. Optionally, the processor 111 can be implemented in at least one hardware form of digital signal processing (DSP), field programmable gate array (FPGA), and programmable logic array (PLA). The processor 111 can integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes the operating system, user interface, and computer programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 111, but may be implemented separately through a communication chip. Specifically, the method described in the above embodiments may be executed by one or more processors 111 .
[0207] For some embodiments, the memory 112 may include a random access memory (RAM) or a read-only memory (ROM). The memory 112 may be used to store instructions, programs, codes, code sets, or instruction sets. The memory 112 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function, instructions for implementing the following various method embodiments, etc. The data storage area may also store data created by the electronic device 110 during use, etc.
[0208] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A data storage method, characterized in that: include: In response to a file write request, data to be written and index information are obtained, wherein the index information includes a plurality of file numbers and a first position parameter, the plurality of file numbers correspond one-to-one to a plurality of storage spaces, the first position parameter is used to represent a file number corresponding to a first storage space written most recently, and the first storage space is one of the plurality of storage spaces; Acquire a first data amount of data currently stored in a first storage space corresponding to the first position parameter; When the first data amount is equal to a first threshold, taking a next position parameter adjacent to the first position parameter as a first target position, wherein the first threshold is used to represent a maximum storage capacity corresponding to the first storage space; The data to be written is written into the target storage space corresponding to the first target position, and the first position parameter in the index information is updated to the first target position.
2. The method according to claim 1, characterized in that The step of taking the next position parameter adjacent to the first position parameter as the first target position when the first data amount is equal to the first threshold value includes: When the first data amount is equal to a first threshold, adding 1 to the first position parameter to obtain a first value; The remainder after dividing the first value by a second threshold is used as the first target position, wherein the second threshold is the amount of storage space.
3. The method according to claim 1, characterized in that Each storage space is divided into a plurality of package data spaces, the index information further includes a second position parameter and a designated package data space sequence number, wherein the second position parameter is used to represent a file sequence number corresponding to the second storage space read most recently, and the method further includes: In response to a data read request, determining a second storage space corresponding to the second location parameter; Determine, in the second storage space, a designated packet data space corresponding to the designated packet data space sequence number; Reading the data stored in the designated packet data space; The designated packet data space sequence number in the index information is updated to the next packet data space sequence number adjacent to the designated packet data space sequence number.
4. The method according to claim 3, characterized in that The updating of the designated packet data space sequence number in the index information to the next packet data space sequence number adjacent to the designated packet data space sequence number comprises: In the case where the designated packet data space sequence number is a third threshold, taking the next position parameter adjacent to the second position parameter as the second target position, wherein the third threshold is the maximum value of the packet data space sequence number corresponding to the packet data space in the second storage space; The second position parameter in the index information is updated to the second target position, and the designated packet data space sequence number in the index information is updated to the initial address.
5. The method according to claim 4, characterized in that When the designated packet data space sequence number is the third threshold, taking the next position parameter adjacent to the second position parameter as the second target position includes: When the designated packet data sequence number is the third threshold, adding 1 to the second position parameter to obtain a second value; The remainder after dividing the second value by a second threshold is used as the second target position, wherein the second threshold is the amount of storage space.
6. The method according to claim 1, characterized in that The step of obtaining the data to be written and the index information in response to the file writing request includes: sequentially determining a file write request from a write request sequence as a target file write request, wherein the write request sequence includes a plurality of file write requests; In response to the target file write request, obtaining the data to be written and the index information; After writing the data to be written into the target storage space corresponding to the first target position and updating the first position parameter in the index information to the first target position, the method further includes: Return to execute the step of sequentially determining a file write request from the write request sequence as the target file write request and subsequent steps until each file write request in the write request sequence is used as the target file write request.
7. The method according to claim 6, characterized in that Before determining one file write request in sequence from the write request sequence as the target file write request, the method further includes: Get the initial data set; The initial data set is segmented based on a fourth threshold value to obtain a plurality of data to be written and an arrangement order of each data to be written, each data to be written corresponds to a file write request, wherein the fourth threshold value is used to characterize the storage capacity of each packet data space in the storage space; The plurality of file write requests are arranged in the order of arrangement of the to-be-written data corresponding to each file write request to obtain the write request sequence.
8. The method according to claim 1, characterized in that: The step of obtaining the data to be written and the index information in response to the file writing request includes: In response to a file writing request, obtaining data to be written; Acquire the index information from the first index file; In the case that the index information is not successfully obtained from the first index file, the index information is obtained from a second index file, wherein the second index file is a backup file of the first index file.
9. The method according to claim 1, characterized in that: Writing the data to be written into the target storage space corresponding to the first target location includes: deleting data stored in the target storage space corresponding to the first target location; The data to be written is written into the target storage space corresponding to the first target location.
10. A data storage device, characterized in that: include: A first acquisition unit is used to obtain the data to be written and index information in response to a file write request, wherein the index information includes a plurality of file numbers and a first position parameter, the plurality of file numbers correspond to a plurality of storage spaces one by one, the first position parameter is used to represent the file number corresponding to the first storage space written most recently, and the first storage space is one of the plurality of storage spaces; a second acquisition unit, configured to acquire a first data volume of data currently stored in a first storage space corresponding to the first position parameter; a first target position determining unit, configured to, when the first data amount is equal to a first threshold, use a next position parameter adjacent to the first position parameter as a first target position, wherein the first threshold is used to represent a maximum storage capacity corresponding to the first storage space; A writing unit is used to write the data to be written into a target storage space corresponding to the first target position, and update the first position parameter in the index information to the first target position.
11. An electronic device, characterized in that: include: one or more processors; Memory; One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1-9.
Citation Information
Patent Citations
File storage equipment, method and device for small-capacity Nor flash and medium
CN115617769A
Storage space management method of Flash memory and data read-write system
CN117194279A
Data writing method and device, storage medium and electronic equipment
CN118819404A
Reprogrammable Non-Volatile Memory Systems With Indexing of Directly Stored Data Files
US20070033374A1
Systems and methods for reducing database index contention and generating unique database identifiers
US9122741B1