Methods, apparatus, and devices for querying and storing data in NAND Flash
By recording the storage time and count value of data frames in NAND Flash, a leapfrog approach is used to quickly locate the data frame of the target time unit, solving the problem of data search time and resource waste in the existing technology and improving search efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WEICHAI POWER CO LTD
- Filing Date
- 2022-12-20
- Publication Date
- 2026-05-26
AI Technical Summary
When searching for data in NAND Flash, current technology requires reading all the data into the application layer database, which wastes time and resources and affects user experience.
When storing data in NAND Flash, the storage time of each data frame and the number of storage frames under a preset time unit are recorded. The data frame of the target time unit is quickly located by leapfrogging, and storage areas that do not meet the query target are skipped.
This enables quick retrieval of data in a specific time unit within NAND Flash, saving query time and resources and improving user experience.
Smart Images

Figure CN115826868B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method, apparatus and device for querying and storing data in NAND Flash. Background Technology
[0002] NAND Flash is a type of non-volatile flash memory. Due to its advantages such as large capacity and fast rewrite speed, it is suitable for storing large amounts of data and has therefore been increasingly widely used in the industry. For example, embedded products such as digital cameras and compact USB flash drives use NAND Flash. When storing effective data, NAND Flash typically uses a real-time clock (RTC) chip to store a timestamp in the data frame. The timestamp records the time when the data frame containing that timestamp was stored.
[0003] Currently, to retrieve data from NAND Flash within a specific time unit (such as minutes, hours, days, months, or years), all data in the NAND Flash must be read into the application layer database, and then the required data must be retrieved from the application layer database. However, reading all data from NAND Flash consumes significant time, storage, and processing resources, negatively impacting the user experience when retrieving data from NAND Flash.
[0004] Therefore, there is an urgent need to provide a technical solution that can more conveniently and quickly search for data in NAND Flash, saving time and other resources when searching for data in NAND Flash. Summary of the Invention
[0005] This application provides a method, apparatus, and device for querying and storing data in NAND Flash. By saving the storage time of each data frame and the number of data frames stored in a preset time unit when storing data in NAND Flash, it makes it faster and more convenient to find the data frame corresponding to a certain value of the time unit in NAND Flash.
[0006] In a first aspect, this application provides a method for querying data in NAND Flash, characterized in that the method includes:
[0007] A query request is obtained, the query request including a target time, the target time being a target value in a preset time unit, the query request being used to request the data stored in NAND Flash at the target time;
[0008] Determine whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time;
[0009] If they do not match, then the data frame indicated by the first count value of the first data frame will be leapfrog forward from the first logical address as the first data frame, the logical address of the first data frame will be recorded as the first logical address, and the process of determining whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time will continue until the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time.
[0010] If a match is found, target data matching the target storage time is obtained from the NAND Flash, the target data including data frames that jump backward from the first logical address by a number of jumps less than the first count value.
[0011] Optionally, the preset time unit includes any one of the following: minute, hour, day, month, or year.
[0012] Optionally, the method further includes:
[0013] Receive a first storage request, the first storage request including a second data frame;
[0014] Store the second data frame to the second logical address, and record the second storage time of the second data frame, as well as the second count value of the stored data frame in the time unit where the second storage time is located;
[0015] Receive a second storage request, the second storage request including a third data frame;
[0016] The third data frame is stored in a third logical address, and the third storage time of the third data frame and the third count value of the stored data frame in the time unit where the third storage time is located are recorded. The third logical address is 1 greater than the second logical address.
[0017] Wherein, if the second storage time and the third storage time belong to the same value in the time unit, then the third count value is 1 greater than the second data value; if the second storage time and the third storage time belong to different values in the time unit, then the third count value is equal to 1.
[0018] Optionally, the storage space of the first data frame in the NAND Flash includes an information area and a data area. The information area includes the first storage time, the first logical address, and the first count value. The data area includes the first data frame.
[0019] Secondly, this application also provides a method for storing data in NAND Flash, the method comprising:
[0020] Receive a first storage request, the first storage request including a first data frame;
[0021] The first data frame is stored in the first logical address, and the first storage time of the first data frame and the first count value of the stored data frame corresponding to the first storage time in the storage interval indicated by the first logical address are recorded.
[0022] Add 1 to the first logical address to obtain the second logical address;
[0023] Receive a second storage request, the second storage request including a second data frame;
[0024] The second data frame is stored in the second logical address, and the second storage time of the second data frame and the second count value of the stored data frame corresponding to the second storage time in the storage interval indicated by the second logical address are recorded. If the second storage time and the first storage time belong to the same value in the time unit, then the second count value is the first data value plus 1. If the second storage time and the first storage time belong to different values in the time unit, then the second count value is equal to 1.
[0025] Thirdly, this application also provides an apparatus for querying data in NAND Flash, the apparatus comprising:
[0026] The obtaining unit is used to obtain a query request, the query request including a target time, the target time being a target value of a preset time unit, the query request being used to request to query the data of the target time stored in NAND Flash;
[0027] The judgment unit is used to determine whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time.
[0028] The frog-jump unit is used to, if there is no match, jump forward from the first logical address to the data frame indicated by the first count value of the first data frame as the first data frame, record the logical address of the first data frame as the first logical address, and continue to execute the step of determining whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time, until the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time;
[0029] The query unit is configured to, if a match is found, obtain target data from the NAND Flash that matches the target storage time, wherein the target data includes data frames that jump backward from the first logical address by a number of jumps less than the first count value.
[0030] Optionally, the preset time unit includes any one of the following: minute, hour, day, month, or year.
[0031] Optionally, the device further includes:
[0032] A first receiving unit is configured to receive a first storage request, wherein the first storage request includes a second data frame;
[0033] The first storage unit is used to store the second data frame to the second logical address, and record the second storage time of the second data frame, and the second count value of the stored data frame in the time unit where the second storage time is located;
[0034] The second receiving unit is configured to receive a second storage request, wherein the second storage request includes a third data frame.
[0035] The second storage unit is used to store the third data frame to the third logical address, and record the third storage time of the third data frame, and the third count value of the stored data frame in the time unit where the third storage time is located. The third logical address is 1 greater than the second logical address.
[0036] Wherein, if the second storage time and the third storage time belong to the same value in the time unit, then the third count value is 1 greater than the second data value; if the second storage time and the third storage time belong to different values in the time unit, then the third count value is equal to 1.
[0037] Optionally, the storage space of the first data frame in the NAND Flash includes an information area and a data area. The information area includes the first storage time, the first logical address, and the first count value. The data area includes the first data frame.
[0038] Fourthly, this application also provides an apparatus for storing data in NAND Flash, the apparatus comprising:
[0039] A first receiving unit is configured to receive a first storage request, wherein the first storage request includes a first data frame;
[0040] The first storage unit is used to store the first data frame to a first logical address, and to record the first storage time of the first data frame and the first count value of the stored data frame corresponding to the first storage time in a preset time unit in the storage area indicated by the first logical address.
[0041] The processing unit is configured to increment the first logical address by 1 to obtain the second logical address;
[0042] The second receiving unit is configured to receive a second storage request, the second storage request including a second data frame;
[0043] The second storage unit is used to store the second data frame to the second logical address, and to record the second storage time of the second data frame in the storage interval indicated by the second logical address, and the second count value of the stored data frame corresponding to the second storage time in the time unit. If the second storage time and the first storage time belong to the same value in the time unit, then the second count value is the first data value plus 1. If the second storage time and the first storage time belong to different values in the time unit, then the second count value is equal to 1.
[0044] Fifthly, this application also provides an electronic device, which includes a processor and a memory:
[0045] The memory is used to store computer programs;
[0046] The processor is configured to execute the method described in the first or second aspect above according to the computer program.
[0047] Sixthly, this application also provides a computer-readable storage medium, characterized in that the computer-readable storage medium is used to store a computer program, the computer program being used to perform the method described in the first or second aspect above.
[0048] Therefore, this application has the following beneficial effects:
[0049] This application provides a method for querying data in NAND Flash. The method may include, for example, obtaining a query request, the query request including a target time, the target time being a target value in a preset time unit, the query request being used to request data stored in the NAND Flash at the target time; determining whether the first storage time of a first data frame corresponding to a first logical address in the NAND Flash matches the target time; if they do not match, then taking the data frame indicated by a first count value of the first data frame leaping forward from the first logical address as the first data frame, recording the logical address of the first data frame as the first logical address, and continuing to determine whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time, until the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time; if they match, then obtaining target data matching the target storage time from the NAND Flash, the target data including data frames leaping forward from the first logical address by a number of leaps less than the first count value. In this way, when storing data frames in NAND Flash, the data frames stored in each time unit are counted according to a preset time unit (such as date), and the count value corresponding to the data frame is recorded. This allows for a leapfrog search based on the count value of the time unit when querying data of a certain value (such as a certain day) stored in NAND Flash. This skips intermediate storage areas that do not meet the search target, achieving the purpose of quickly locating and retrieving the data to be queried, and saving time and other resources such as searching for data stored under a certain value of the time unit in NAND Flash. Attached Figure Description
[0050] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0051] Figure 1 This is a schematic diagram of the storage space for a data frame in a NAND Flash memory.
[0052] Figure 2 This is a flowchart illustrating a method for storing data in NAND Flash according to an embodiment of this application;
[0053] Figure 3 A schematic diagram of the storage space of a data frame in a NAND Flash memory according to an embodiment of this application;
[0054] Figure 4 This is a flowchart illustrating a method for querying data in NAND Flash according to an embodiment of this application;
[0055] Figure 5 A schematic diagram illustrating an example of querying data in NAND Flash provided in an embodiment of this application;
[0056] Figure 6 This is a schematic diagram of the structure of a device for querying data in NAND Flash according to an embodiment of this application;
[0057] Figure 7 This is a schematic diagram of the structure of a NAND Flash data storage device according to an embodiment of this application;
[0058] Figure 8 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation
[0059] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the embodiments of this application will be further described in detail below with reference to the accompanying drawings and specific implementation methods. It should be understood that the specific embodiments described herein are merely for explaining this application and are not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to this application are shown in the accompanying drawings, not the entire structure.
[0060] NAND flash memory has a relatively large storage space. When storing data, it typically packages 512 bytes (B) of data into a single data frame, storing the data frame by frame. Each data frame occupies one unit of storage space in the NAND flash memory. For example, you can refer to [reference needed]. Figure 1The storage space includes an information area and a data area. The information area may include the storage time of the data frames stored in the storage space and the logical address of the storage space. The data area includes the specific data of the data frames. The storage time format can be: year / month / day / hour / minute / second. Optionally, to improve the security and reliability of data stored in NAND Flash, each storage space may also include a verification area. The verification area may include, for example, the Cyclic Redundancy Check (CRC) value of the data frames. Taking storing data 1 in NAND Flash as an example, the current storage process may include: starting to write data in data 1 at the position indicated by the current logical address (which can also be represented by ID). Assuming the current ID = 15, then, the first 512B data frame 1 of data 1 is written to storage space 1 with ID = 15, and ID = ID + 1 = 16 is updated; the second 512B data frame 2 of data 1 is written to storage space 2 with ID = 16, and ID = ID + 1 = 17 is updated; and so on, until all data frames of data 1 are written to NAND Flash. The information area 1 in storage space 1 may include storage time 1 (e.g., 20:44:18 on December 14, 2022) and ID=15, and the data area 1 in storage space 1 may include data frame 1; the information area 2 in storage space 2 may include storage time 2 (e.g., 20:54:15 on December 14, 2022) and ID=16, and the data area 2 in storage space 2.
[0061] Currently, the way NAND Flash stores data requires that if you want to query the data stored in NAND Flash at a specific time (such as December 13, 2022) within a specific time unit (such as date), you need to read all the data stored in the underlying layer (i.e., NAND Flash) to the application layer database, and then filter the data in the application layer database according to the query requirements. In this query method, reading all the underlying data consumes a lot of time, storage, and processing resources, which significantly impacts the user experience.
[0062] Based on this, this application provides a method for data storage and querying in NAND Flash. During data storage, a COUNT value is introduced to quickly locate the storage location of data at a specific time within a preset time unit during data querying. Taking a day as an example, for each new data frame stored on the same day, the COUNT value corresponding to that data frame is incremented by 1 to record the number of data frames stored on the current date. When the date is updated to the next day, the COUNT value becomes 1, and the count restarts. Thus, when querying data (or the location of data) stored in NAND Flash on a certain day, first, it is determined whether the storage time in the storage space pointed to by the latest ID matches the query date. If they do not match, the COUNT value recorded in the storage space pointed to by the latest ID directly jumps to the storage space where the last data frame of the previous date is located, skipping multiple storage areas that do not meet the query date. This leapfrog approach achieves rapid data location and querying.
[0063] As an example, the method may include: obtaining a query request, the query request including a target time, the target time being a target value in a preset time unit, the query request being used to request data stored in NAND Flash at the target time; determining whether the first storage time of a first data frame corresponding to a first logical address in the NAND Flash matches the target time; if they do not match, then taking the data frame indicated by the first count value of the first data frame leaping forward from the first logical address as the first data frame, recording the logical address of the first data frame as the first logical address, and continuing to determine whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time, until the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time; if they match, then obtaining target data matching the target storage time from the NAND Flash, the target data including data frames leaping forward from the first logical address by a number of leaps less than the first count value.
[0064] In this way, when storing data frames in NAND Flash, the data frames stored in each time unit are counted according to a preset time unit (such as date), and the count value corresponding to the data frame is recorded. This allows for a leapfrog search based on the count value of the time unit when querying data of a certain value (such as a certain day) stored in NAND Flash. This skips intermediate storage areas that do not meet the search target, achieving the purpose of quickly locating and retrieving the data to be queried, and saving time and other resources such as searching for data stored under a certain value of the time unit in NAND Flash.
[0065] To facilitate understanding of the specific implementation of the NAND Flash data storage method provided in the embodiments of this application, the following description will be provided in conjunction with the accompanying drawings.
[0066] It should be noted that the entity implementing this NAND Flash data storage method can be the NAND Flash data storage device provided in the embodiments of this application, which can be carried in an electronic device or a functional module of an electronic device. The electronic device in the embodiments of this application can be any device capable of implementing the NAND Flash data storage method in the embodiments of this application.
[0067] Figure 2 This is a schematic flowchart illustrating a method for storing data in NAND Flash according to an embodiment of this application. This method can be applied to a device for storing data in NAND Flash, which can be, for example, […]. Figure 6 The method can be applied to the NAND Flash storage data device 600 shown (i.e., the method can be applied to the NAND Flash storage data device 600), or the NAND Flash storage data device can also be integrated into... Figure 8 In the electronic device 800 shown (i.e., the method can also be applied to electronic device 800).
[0068] like Figure 2 As shown, the method may include, for example, S101 to S105:
[0069] S101, Receive a first storage request, the first storage request including a first data frame.
[0070] The first storage request is used to request the storage of a first data frame in the NAND Flash. The first data frame can be a collective term for at least one data frame to be stored in the first storage request.
[0071] S102, store the first data frame to the first logical address, and record the first storage time of the first data frame and the first count value of the stored data frame corresponding to the first storage time in the storage interval indicated by the first logical address.
[0072] The storage space corresponding to each data frame in NAND Flash can be as follows: Figure 3 As shown, compared to Figure 1 The storage space shown Figure 3 The storage space shown includes a COUNT value for recording each value in a preset time unit. The COUNT value can be located in the information area of the data frame's storage space, for example, after the ID field in the information area.
[0073] NAND flash memory can be configured with preset time units to meet the needs of subsequent operations such as querying. Preset time units can include any of the following: minutes, hours, days, months, or years. Different NAND flash memory types can be configured with different time units. The following description uses days as an example; the methods for storing and querying data in NAND flash memory are similar for other time units.
[0074] In a specific implementation, S102 may include: starting to write a first data frame at the position indicated by the current logical address (i.e., the first logical address), and recording a first storage time and a first count value in the storage space where the first data frame is located (i.e., the storage space indicated by the first logical address). The first storage time is the time when the first data frame is written to the storage space indicated by the first logical address, for example, December 14, 2022, at 20:44:18. If the first data frame is the Nth data frame written on December 14, 2022, then the first count value can be equal to N, where N is an integer greater than or equal to 1. If the first data frame is not the first data frame written on December 14, 2022, then the first count value can be obtained by adding 1 to the calculated value corresponding to the previously written data frame.
[0075] Following S102, the storage space of the first data frame in the NAND Flash includes an information area and a data area. The information area includes a first storage time, a first logical address, and a first count value; the data area includes the first data frame. The storage space of the first data frame may also include a verification area, which may, for example, include a first CRC value corresponding to the first data frame. This first CRC value is used for verification when reading the first data frame from the NAND Flash.
[0076] S103, add 1 to the first logical address to obtain the second logical address.
[0077] After storing the first data frame to be stored into the NAND Flash, step S103 can be executed, that is, updating the current logical address so that the updated current logical address indicates the storage location of the next data frame to be stored in the NAND Flash. The method for updating the current logical address can be, for example, by adding 1 to the first logical address in step S103 to obtain the second logical address, where the second logical address is the updated logical address.
[0078] S104, Receive a second storage request, the second storage request including a second data frame.
[0079] S105, store the second data frame to the second logical address, and record the second storage time of the second data frame and the second count value of the stored data frame corresponding to the second storage time in the storage interval indicated by the second logical address. If the second storage time and the first storage time belong to the same value in the time unit, then the second count value is the first data value plus 1. If the second storage time and the first storage time belong to different values in the time unit, then the second count value is equal to 1.
[0080] It should be noted that the second storage request in S104 can be a storage request received after S101. The second storage request is used to request the storage of a second data frame in the NAND Flash. The second data frame can be a collective term for at least one data frame to be stored in the second storage request.
[0081] In a specific implementation, S105 may include: starting to write a second data frame at the position indicated by the current logical address (i.e., the second logical address), and recording a second storage time and a second count value in the storage space where the second data frame is located (i.e., the storage space indicated by the second logical address). The second storage time is the time it takes to write the second data frame to the storage space indicated by the second logical address. Assuming that the first data frame was written to the NAND Flash before and adjacent to the second data frame, and the first storage time of the first data frame is 20:55:15 on December 14, 2022, and the first count value is N, if the second data frame was written on December 14, 2022, then the second count value can be equal to (N+1); if the second data frame was written on December 15, 2022, then the second count value can be 1.
[0082] Following step S105, the NAND Flash memory includes at least storage space for a first data frame and storage space for a second data frame. The information area of the second data frame's storage space includes a second storage time, a second logical address, and a second count value; the data area of the second data frame's storage space includes the second data frame itself. The storage space for the second data frame may also include a verification area, which may, for example, include a second CRC value corresponding to the second data frame. This second CRC value is used for verification when reading the second data frame from the NAND Flash memory.
[0083] As can be seen, the NAND Flash data storage method provided in this application embodiment prepares for the rapid location and retrieval of data in NAND Flash. It makes it possible to quickly locate the storage location of data with a specific value in a preset time unit in NAND Flash and easily read it using a leapfrog approach. There is no need to read all the data from the bottom layer to the application layer database and then perform data query operations. The location and reading of the data to be queried are performed directly at the bottom layer, and the read data is transmitted to the host computer, saving resources such as query time, transmission time, storage load, bus load, and processing load.
[0084] Figure 4 This is a schematic flowchart illustrating a method for querying data in NAND Flash memory, provided as an embodiment of this application. This method can be applied to a device for querying data in NAND Flash memory, which can be, for example, […]. Figure 7 The method can be applied to the device 700 for querying data in NAND Flash (i.e., the method can be applied to the device 700 for querying data in NAND Flash), or the device for querying data in NAND Flash can also be integrated into Figure 8 In the electronic device 800 shown (i.e., the method can also be applied to electronic device 800).
[0085] like Figure 4 As shown, the method may include, for example, S201 to S204:
[0086] S201, Obtain a query request. The query request includes a target time, which is a target value in a preset time unit. The query request is used to request the data of the target time stored in NAND Flash.
[0087] If the preset time unit is minutes, and the target time is specified to a specific minute of a specific hour on a specific day, for example, the target time could be 5:44 AM on December 14, 2022, then the query request would be used to retrieve data stored in NAND Flash at that minute. If the preset time unit is hours, and the target time is specified to a specific hour of a specific day, for example, the target time could be 5:00 AM on December 14, 2022, then the query request would be used to retrieve data stored in NAND Flash at that specific hour. If the preset time unit is days, and the target time is specified to a specific day, for example... If the target time is December 14, 2022, then the query request will be used to retrieve data stored in NAND Flash on that date. If the preset time unit is month, and the target time is specified to a specific month of a specific year (e.g., December 2022), then the query request will be used to retrieve data stored in NAND Flash within that month. If the preset time unit is year, and the target time is specified to a specific year (e.g., 2022), then the query request will be used to retrieve data stored in NAND Flash within that year. The following explanation uses a date as the preset time unit, with a specific day as the target time.
[0088] S202, determine whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time. If they do not match, execute S203; if they match, execute S204.
[0089] S203, take the data frame indicated by the first count value of the first data frame from the first logical address as the first data frame, record the logical address of the first data frame as the first logical address, and return to execute S202.
[0090] S204, obtain target data matching the target storage time from the NAND Flash, the target data including data frames that jump forward from the first logical address by a number of jumps less than the first count value.
[0091] The first logical address is the current logical address of the NAND Flash (or the latest logical address), which is the logical address corresponding to the most recently stored data frame. Assuming S101 to S105 occur sequentially, if S201 occurs between S102 and S104, then the first logical address in S202 is the same as the first logical address in S102; if S201 occurs after S105, but no other data frames have been stored yet, then the first logical address in S202 is the same as the second logical address in S105.
[0092] In a specific implementation, S202 may include: determining the storage space for storing the first data frame based on the first logical address; reading the first storage time from the information area of the storage space of the first data frame; determining whether the first storage time is the target time; if so, determining that the first storage time matches the target time; if not, determining that the first storage time does not match the target time.
[0093] If the first storage time matches the target time, then the first data frame is determined to belong to the target of the query request, and S204 can be executed.
[0094] For S204, in one scenario, a first count value can be read from the information area of the storage space of the first data frame, and (first count value - 1) data frames forward from the first data frame can be read as target data matching the target time. Alternatively, in another scenario, each data frame can be read forward from the first data frame. Reading each data frame can mean: before reading each data frame, verifying whether the storage time of the data frame matches the target time; if they match, then reading the data frame; if they do not match, then stopping reading and obtaining the target data based on all the read data.
[0095] If the first storage time does not match the target time, it is determined that the target of the query request should be before the first storage time. Moreover, data frames with the same time unit as the first storage time are not the target of the query request. Therefore, in order to achieve fast location and query, S203 can be executed to continue the search by leapfrogging.
[0096] For S203, we can jump forward from the first logical address by the first count value, update the logical address where the current jump ends to the first logical address, and use the data frame indicated by the updated first logical address as the first data frame. Then we continue to execute the judgment in S202. This process repeats from S202 to S203 until the judgment result of S202 is a match. When the judgment result of S202 is a match, we complete the current search based on S204.
[0097] For example, taking the storage space of a data frame, which includes storage time, logical address, counter value, and data frame, as an example, see [link to relevant documentation]. Figure 5The method for querying data in NAND Flash provided in the embodiments of this application will be described by way of example. Assuming the preset time unit is date (i.e., day), the target time in the query request is October 1, 2022. The storage time of the latest data frame 1 stored in the NAND Flash is October 3, 2022, with a logical address of 105 and a count value of 76. The logical address corresponding to the first data frame stored on October 3, 2022 is 30, with a count value of 1. The logical address corresponding to the last data frame stored on October 2, 2022 is 29, with a count value of 19. The logical address corresponding to the first data frame stored on October 2, 2022 is 11, with a count value of 1. The logical address corresponding to the last data frame stored on October 1, 2022 is 10, with a count value of 11. The logical address corresponding to the first data frame stored on October 1, 2022 is 0, with a count value of 1. The logical address corresponding to the second data frame stored on October 1, 2022 is 1, with a count value of 2. After receiving the query request, based on the first logical address 105, it is first determined that the storage time of the data frame indicated by the first logical address 105 is not October 1, 2022. Therefore, it skips forward 76 hops to the first count value corresponding to the first logical address to obtain the updated first logical address 29. It is then determined that the storage time of the data frame indicated by the first logical address 29 is not October 1, 2022. Therefore, it continues to skip forward 19 hops to the first count value corresponding to the first logical address to obtain the updated first logical address 10. Finally, it is determined that the storage time of the data frame indicated by the first logical address 10 is October 1, 2022. Therefore, the first count value 11 can be read from the storage space indicated by the first logical address 10, and (11-1=10) data frames forward from the data frame indicated by the first logical address 10 can be read as the target data matching the target time. The target data could be, for example,... Figure 5 Data frames 1 to 11 in the data.
[0098] It should be noted that when all the storage space of NAND Flash is used up, the value of the logical address jumps to 0, and storage starts again from the beginning position.
[0099] It should be noted that, in order to record the latest logical address (i.e., the first logical address or the current logical address), the device containing the NAND Flash will save the latest logical address in the microcontroller's built-in electrically erasable programmable read-only memory (EEPROM) when it is powered off normally. When the device is powered on again, it will first read the latest logical address from the built-in EEPROM to record the position to be written to the next data frame.
[0100] As can be seen, the method provided in this application adopts a leapfrog approach, that is, as long as the storage time of the data frame indicated by the first logical address does not match the target time, then considering that other data frames whose storage time is the same day as the data frame are also not the target of this query, these other data frames whose storage time is the same day as the data frame are not queried, thus saving query time and other resources, making it faster and more convenient to query data of the target time from the bottom layer.
[0101] Accordingly, see Figure 6 This application embodiment also provides a device 600 for querying data in NAND Flash, the device 600 may include:
[0102] The obtaining unit 601 is used to obtain a query request, the query request including a target time, the target time being a target value of a preset time unit, the query request being used to request to query the data of the target time stored in NANDFlash;
[0103] The judgment unit 602 is used to determine whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time;
[0104] The frog-jumping unit 603 is used to, if there is no match, jump forward from the first logical address to the data frame indicated by the first count value of the first data frame as the first data frame, record the logical address of the first data frame as the first logical address, and continue to execute the step of judging whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time, until the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time;
[0105] The query unit 604 is configured to, if a match is found, obtain target data matching the target storage time from the NAND Flash, wherein the target data includes data frames that jump backward from the first logical address by a number of jumps less than the first count value.
[0106] Optionally, the preset time unit includes any one of the following: minute, hour, day, month, or year.
[0107] Optionally, the device 600 further includes:
[0108] A first receiving unit is configured to receive a first storage request, wherein the first storage request includes a second data frame;
[0109] The first storage unit is used to store the second data frame to the second logical address, and record the second storage time of the second data frame, and the second count value of the stored data frame in the time unit where the second storage time is located;
[0110] The second receiving unit is configured to receive a second storage request, wherein the second storage request includes a third data frame.
[0111] The second storage unit is used to store the third data frame to the third logical address, and record the third storage time of the third data frame, and the third count value of the stored data frame in the time unit where the third storage time is located. The third logical address is 1 greater than the second logical address.
[0112] Wherein, if the second storage time and the third storage time belong to the same value in the time unit, then the third count value is 1 greater than the second data value; if the second storage time and the third storage time belong to different values in the time unit, then the third count value is equal to 1.
[0113] Optionally, the storage space of the first data frame in the NAND Flash includes an information area and a data area. The information area includes the first storage time, the first logical address, and the first count value. The data area includes the first data frame.
[0114] It should be noted that the specific implementation method and technical effects achieved by the device 600 can be found in [reference needed]. Figure 4 The relevant descriptions in the methods shown.
[0115] Accordingly, see Figure 7 This application also provides a NAND Flash storage data device 700, which may include:
[0116] The first receiving unit 701 is configured to receive a first storage request, wherein the first storage request includes a first data frame.
[0117] The first storage unit 702 is used to store the first data frame to a first logical address, and to record the first storage time of the first data frame in the storage interval indicated by the first logical address, and the first count value of the stored data frame corresponding to the first storage time in a preset time unit.
[0118] Processing unit 703 is used to add 1 to the first logical address to obtain the second logical address;
[0119] The second receiving unit 704 is configured to receive a second storage request, the second storage request including a second data frame;
[0120] The second storage unit 705 is used to store the second data frame to the second logical address, and record the second storage time of the second data frame and the second count value of the stored data frame corresponding to the second storage time in the storage interval indicated by the second logical address. If the second storage time and the first storage time belong to the same value in the time unit, then the second count value is the first data value plus 1. If the second storage time and the first storage time belong to different values in the time unit, then the second count value is equal to 1.
[0121] It should be noted that the specific implementation method and technical effects achieved by the device 700 can be found in [reference needed]. Figure 2 The relevant descriptions in the methods shown.
[0122] Furthermore, embodiments of this application also provide an electronic device 800, such as... Figure 8 As shown, the electronic device 800 includes a processor 801 and a memory 802:
[0123] The memory 802 is used to store computer programs;
[0124] The processor 801 is configured to execute according to the computer program. Figure 2 or Figure 4 The methods provided.
[0125] Furthermore, embodiments of this application also provide a computer-readable storage medium for storing a computer program for executing the method provided in embodiments of this application.
[0126] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that all or part of the steps in the methods of the above embodiments can be implemented by means of software plus a general-purpose hardware platform. Based on this understanding, the technical solution of this application can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as a read-only memory (ROM) / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, a server, or a network communication device such as a router) to execute the methods described in various embodiments or some parts of the embodiments of this application.
[0127] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system and device embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions in the method embodiments. The device and system embodiments described above are merely illustrative. Modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0128] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. It should be noted that those skilled in the art can make various improvements and modifications without departing from this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for querying data in NAND Flash, characterized in that, The method includes: A query request is obtained, the query request including a target time, the target time being a target value in a preset time unit, the query request being used to request the data stored in NAND Flash at the target time; Determine whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time; If they do not match, then the data frame indicated by the first count value of the first data frame will be leapfrog forward from the first logical address as the first data frame, and the logical address of the first data frame will be recorded as the first logical address. The process of determining whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time will continue until the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time. The first count value is the count value of the stored data frame corresponding to the preset time unit recorded in the storage area indicated by the first logical address of the first data frame after receiving the storage request including the first data frame. If a match is found, target data matching the target storage time is obtained from the NAND Flash, the target data including data frames that jump forward from the first logical address by a number of jumps less than the first count value.
2. The method according to claim 1, characterized in that, The preset time unit includes any one of the following: minute, hour, day, month, or year.
3. The method according to claim 1, characterized in that, The method further includes: Receive a first storage request, the first storage request including a second data frame; Store the second data frame to the second logical address, and record the second storage time of the second data frame, as well as the second count value of the stored data frame in the time unit where the second storage time is located; Receive a second storage request, the second storage request including a third data frame; The third data frame is stored in a third logical address, and the third storage time of the third data frame and the third count value of the stored data frame in the time unit where the third storage time is located are recorded. The third logical address is 1 greater than the second logical address. Wherein, if the second storage time and the third storage time belong to the same value in the time unit, then the third count value is 1 greater than the second count value; if the second storage time and the third storage time belong to different values in the time unit, then the third count value is equal to 1.
4. The method according to any one of claims 1-3, characterized in that, The storage space of the first data frame in the NAND Flash includes an information area and a data area. The information area includes the first storage time, the first logical address, and the first count value. The data area includes the first data frame.
5. A method for storing data in NAND Flash, characterized in that, The method includes: Receive a first storage request, the first storage request including a first data frame; The first data frame is stored in the first logical address, and the first storage time of the first data frame and the first count value of the stored data frame corresponding to the first storage time in the storage interval indicated by the first logical address are recorded. Add 1 to the first logical address to obtain the second logical address; Receive a second storage request, the second storage request including a second data frame; The second data frame is stored in the second logical address, and the second storage time of the second data frame and the second count value of the stored data frame corresponding to the second storage time in the storage interval indicated by the second logical address are recorded. If the second storage time and the first storage time belong to the same value in the time unit, then the second count value is the first count value plus 1. If the second storage time and the first storage time belong to different values in the time unit, then the second count value is equal to 1.
6. A device for querying data in NAND Flash, characterized in that, The device includes: The obtaining unit is used to obtain a query request, the query request including a target time, the target time being a target value of a preset time unit, the query request being used to request to query the data of the target time stored in NAND Flash; The judgment unit is used to determine whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time; The leapfrog unit is used to, if there is no match, leapfrog forward from the first logical address to the data frame indicated by the first count value of the first data frame as the first data frame, record the logical address of the first data frame as the first logical address, and continue to execute the step of determining whether the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time, until the first storage time of the first data frame corresponding to the first logical address in the NAND Flash matches the target time. The first count value is the count value of the stored data frame corresponding to the preset time unit recorded in the storage area indicated by the first logical address of the first data frame after receiving the storage request including the first data frame. The query unit is configured to, if a match is found, obtain target data matching the target storage time from the NAND Flash, wherein the target data includes data frames that jump backward from the first logical address by a number of jumps less than the first count value.
7. The apparatus according to claim 6, characterized in that, The preset time unit includes any one of the following: minute, hour, day, month, or year.
8. A device for storing data using NAND Flash, characterized in that, The device includes: A first receiving unit is configured to receive a first storage request, wherein the first storage request includes a first data frame; The first storage unit is used to store the first data frame to a first logical address, and to record the first storage time of the first data frame and the first count value of the stored data frame corresponding to the first storage time in a preset time unit in the storage area indicated by the first logical address. The processing unit is configured to increment the first logical address by 1 to obtain the second logical address; The second receiving unit is configured to receive a second storage request, the second storage request including a second data frame; The second storage unit is used to store the second data frame to the second logical address, and to record the second storage time of the second data frame in the storage interval indicated by the second logical address, and the second count value of the stored data frame corresponding to the second storage time in the time unit. If the second storage time and the first storage time belong to the same value in the time unit, then the second count value is the first count value plus 1. If the second storage time and the first storage time belong to different values in the time unit, then the second count value is equal to 1.
9. An electronic device, characterized in that, The electronic device includes a processor and a memory: The memory is used to store computer programs; The processor is configured to perform the method according to any one of claims 1-5 according to the computer program.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program for performing the method according to any one of claims 1-5.