Data storage method and device
Through the initialization of the FLASH chip user area and the management of data pages and transaction pages, the problem of lack of flexible transaction management and stable power-down exception handling in the prior art is solved, and data integrity and system stability are improved.
Patent Information
- Application Number
- CN202411823671.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-12-12
AI Technical Summary
The existing FLASH chips lack flexible transaction management and stable and reliable power-down exception handling process when frequent file updates, which affects system security and stability.
Provides a data storage method, by initializing the user area, managing the updated data page and transaction page according to the data update instructions, including mark management in data formatting, and updating the data area address mapping table and the free area address mapping table.
It realizes flexible configuration of data pages, idle pages and transaction page sizes. Through the modification of transaction tags and structured tags, the integrity of data during the update process is ensured and the stability and service life of the system are improved.
Smart Images

Figure CN119292540B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular to a data storage method and device. Background Art
[0002] In the current chip industry, FLASH chips have been widely used in low-cost, fast-paced practical applications. Due to the large number of COS file types and files in the system, the processing of COS files in the system usually requires FLASH chips. However, due to frequent file updates, FLASH chips need to be erased and written multiple times. However, the existing FLASH chip storage processing method lacks flexible transaction management and stable and reliable power-off exception processing procedures, which affects system security and reduces system stability. Therefore, how to improve system stability is an urgent problem to be solved in the prior art. Summary of the invention
[0003] In order to solve the above technical problems, the present invention provides a data storage method and device.
[0004] To this end, according to a first aspect of the present invention, a data storage method is provided, the method comprising:
[0005] Step S1, power on the chip, determine whether the user area has been initialized, if yes, scan the user area, update the data area address mapping table and the idle area address mapping table according to the scanning result, wait for receiving the data update instruction, and execute step S2 when receiving the data update instruction; if no, initialize the user area, wait for receiving the data update instruction, and execute step S2 when receiving the data update instruction, and the initialization process specifically includes constructing the data area address mapping table and the idle area address mapping table;
[0006] Step S2, determining the logical page number according to the data update instruction, obtaining the physical address corresponding to the logical page number from the data area address mapping table, obtaining the data page to be updated according to the physical address, and determining whether there is a transaction page corresponding to the data page to be updated according to the logical page number, if yes, executing step S3, otherwise executing step S4;
[0007] Step S3, obtaining the transaction page corresponding to the data page to be updated according to the logical page number, copying the data of the obtained transaction page to the memory, modifying the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, writing the updated data into the transaction page corresponding to the data page to be updated, and determining whether the update transaction is completed. If so, executing step S5; otherwise, waiting to receive the data update instruction, executing step S2 when receiving the data update instruction or directly executing step S2;
[0008] Step S4, copy the data of the data page to be updated to the memory, modify the business data and transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, obtain an idle page corresponding to the first physical address in the idle area address mapping table, write the updated data into the obtained idle page to obtain the transaction page, determine whether the update transaction is completed, if so, execute step S5, if not, wait to receive the data update instruction, and execute step S2 when the data update instruction is received, or directly execute step S2;
[0009] Step S5, modify the structured mark value of all data pages to be updated to the sixth preset value, modify the transaction mark value of all transaction pages to the second preset value, use all transaction pages as updated data pages, update the data area address mapping table according to the physical address of the updated data page, update the free area address mapping table according to the physical address of all data pages to be updated, and end.
[0010] According to a second aspect of the present invention, there is provided a data storage device, characterized in that the device comprises:
[0011] A first judging module is used to judge whether the user area is initialized, and if it is judged that the initialization is completed, the first updating module is triggered; if it is judged that the initialization is not completed, the initialization module is triggered;
[0012] The initialization module is used to perform initialization processing on the user area, and the initialization processing specifically includes constructing a data area address mapping table and a free area address mapping table, waiting to receive a data update instruction, and triggering the first determination module when receiving the data update instruction;
[0013] The first updating module is used to scan the user area, update the data area address mapping table and the free area address mapping table according to the scanning result, wait for receiving the data update instruction, and trigger the first determining module when receiving the data update instruction;
[0014] The first determination module is used to determine the logical page number according to the data update instruction, obtain the physical address corresponding to the logical page number from the data area address mapping table, obtain the data page to be updated according to the physical address, and determine whether there is a transaction page corresponding to the data page to be updated according to the logical page number, and trigger the second update module if it is determined that it exists, and trigger the third update module if it is determined that it does not exist;
[0015] The second update module is used to obtain the transaction page corresponding to the data page to be updated according to the logical page number, copy the data of the obtained transaction page to the memory, modify the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, write the updated data into the transaction page corresponding to the data page to be updated, determine whether the current update transaction is completed, if it is determined that the current update transaction is completed, trigger the fourth update module, if it is determined that the current update transaction is not completed, trigger the first determination module;
[0016] The third update module is used to copy the data of the data page to be updated to the memory, modify the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, obtain a free page corresponding to the first physical address in the free area address mapping table, write the updated data into the obtained free page to obtain the transaction page, determine whether the current update transaction is completed, if it is determined that the current update transaction is completed, trigger the fourth update module, if it is determined that the current update transaction is not completed, trigger the first determination module;
[0017] The fourth update module is used to modify the structured mark values of all data pages to be updated to the sixth preset value, modify the transaction mark values of all transaction pages to the second preset value, use all transaction pages as updated data pages, update the data area address mapping table according to the physical addresses of the updated data pages, and update the free area address mapping table according to the physical addresses of all data pages to be updated.
[0018] According to a third aspect of the present invention, a computer device, a memory, a processor and a computer program stored in the memory are provided, and the processor executes the computer program to implement the data storage method described in the first aspect.
[0019] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which a computer program / instruction is stored, and when the computer program / instruction is executed by a processor, the steps of the data storage method described in the first aspect are implemented.
[0020] According to a fifth aspect of the present invention, a computer program product is provided, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the data storage method described in the first aspect.
[0021] The beneficial effects brought about by the technical solution provided by the present invention include at least:
[0022] The present invention provides a data storage method and device, which initializes the user area, manages the updated data pages and transaction pages through the marks in the data formatting according to the update data instruction during the data update process, and completes the update of the data area address mapping table and the free area address mapping table, so that the size of the data page, the free page and the effective free page can be flexibly configured, and the integrity of the data during the update process is guaranteed by modifying the transaction mark and the structured mark. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] For a clearer explanation, the embodiments of the present invention or the prior art are briefly introduced below in conjunction with the accompanying drawings. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0024] Figure 1 This is a flow chart of a data storage method provided by Embodiment 1 of the present invention;
[0025] Figure 2 It is a schematic diagram of the process flow of constructing a data mapping table in a user area in a data storage method provided in Embodiment 2 of the present invention;
[0026] Figure 3 It is a schematic diagram of the process flow of updating user area data in a data storage method provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0027] To make the objectives, technical solutions and advantages of the present invention more clear, embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
[0028] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are only examples of devices and methods consistent with some aspects of the present invention as detailed in the attached claims.
[0029] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings.
[0030] Embodiment 1
[0031] Embodiment 1 of the present invention provides a data storage method, which is applicable to a data storage system including a FLASH chip. Specifically, the present invention mainly relates to data storage in a user area in a FLASH chip; the user area is a space for storing user service data; the user area includes a data area and a free area; the data area includes a plurality of data pages, and the free area includes a plurality of free pages. The data page refers to a page with a certain format in the data area, which is used to store valid service data; the free page refers to a page without a format in the free area, which is used to store cache data in the erasing process; the free area also includes a transaction page, which refers to a free page temporarily occupied when completing a transaction update; the data storage process includes processing flows such as data writing and data erasing;
[0032] like Figure 1 As shown, a data storage method specifically includes:
[0033] Step 101, power on the chip, determine whether the user area has been initialized, if yes, scan the user area, update the data area address mapping table and the free area address mapping table according to the scanning result, wait for receiving the data update instruction, and execute step 102 when receiving the data update instruction, if no, initialize the user area, wait for receiving the data update instruction, and execute step 102 when receiving the data update instruction, the initialization process specifically includes constructing the data area address mapping table and the free area address mapping table;
[0034] Step 102, determine the logical page number according to the data update instruction, obtain the physical address corresponding to the logical page number from the data area address mapping table, obtain the data page to be updated according to the physical address, and determine whether there is a transaction page corresponding to the data page to be updated according to the logical page number. If so, execute step 103, otherwise execute step 104;
[0035] Step 103, according to the logical page number, obtain the transaction page corresponding to the data page to be updated, copy the data of the obtained transaction page to the memory, modify the business data and transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, write the updated data into the transaction page corresponding to the data page to be updated, and determine whether the update transaction is completed. If so, execute step 105; otherwise, wait for receiving the data update instruction. When the data update instruction is received, execute step 102, or directly execute step 102;
[0036] Step 104, copy the data of the data page to be updated to the memory, modify the business data and transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, obtain a free page corresponding to the first physical address in the free area address mapping table, write the updated data into the obtained free page to obtain the transaction page, and determine whether the update transaction is completed. If so, execute step 105, otherwise wait for receiving the data update instruction. When the data update instruction is received, execute step 102 or directly execute step 102;
[0037] Step 105: modify the structured mark values of all data pages to be updated to the sixth preset value, modify the transaction mark values of all transaction pages to the second preset value, use all transaction pages as updated data pages, update the data area address mapping table according to the physical addresses of the updated data pages, and update the free area address mapping table according to the physical addresses of all data pages to be updated, and end;
[0038] In one practicable manner, the user area includes a data area and a free area, and initializing the user area specifically includes:
[0039] Step A1, formatting and assigning physical addresses to data pages in the data area, and assigning physical addresses to free pages in the free area;
[0040] Step A2: construct a data area address mapping table and a free area address mapping table according to the allocated physical addresses.
[0041] An implementable method for updating the data area address mapping table and the free area address mapping table according to the scan result specifically includes:
[0042] A physical page mapping relationship is constructed according to the scanning result and stored in a free area address mapping table, a data area address mapping table or an update data table;
[0043] Determine whether there is a physical page mapping relationship in the update data table. If yes, update the free area address mapping table and the data area address mapping table according to the physical page mapping relationship in the update data table. Otherwise, end.
[0044] Specifically, constructing a physical page mapping relationship according to the scan result and storing it in a free area address mapping table, a data area address mapping table or an update data table specifically includes:
[0045] Step B1, determining whether the structured tag value in the scanned physical page is a fifth preset value, if yes, obtaining the transaction tag value in the physical page, and executing step B2, otherwise treating the physical page as an idle page, and storing the physical address corresponding to the physical page in the idle area address mapping table;
[0046] Step B2, determine whether the transaction mark value in the physical page is a second preset value. If so, treat the physical page as a data page, and store the physical address of the physical page and the logical page number as a mapping relationship in the data area address mapping table; otherwise, treat the physical page as a transaction page, and store the physical address of the physical page and the logical page number as a mapping relationship in the update data table.
[0047] Specifically, updating the free area address mapping table and the data area address mapping table according to the physical page mapping relationship in the update data table specifically includes:
[0048] Step C1, obtaining a physical page according to the logical page number in the physical page mapping relationship in the update data table, and determining whether there is a physical page with a transaction mark value of a fourth preset value in the obtained physical page, if so, executing step C2, otherwise executing step C3;
[0049] Step C2, modifying the structured mark values of all physical pages in the data area address mapping table that have the same logical page number as that in the update data table to the sixth preset value, modifying the transaction mark values of all physical pages corresponding to the physical addresses in the update data table to the second preset value, storing the physical addresses in the data area address mapping table that correspond to the logical page numbers in the update data table to the free area address mapping table, storing the physical page mapping relationship in the update data table to the data area address mapping table, and clearing the update data table;
[0050] Step C3: modify the structured identifiers of all physical pages corresponding to the physical addresses in the update data table to the sixth preset value, and store the physical addresses in the update data table into the free area address mapping table.
[0051] In one practicable manner, determining the logical page number according to the data update instruction is specifically as follows: obtaining the logical address in the data update instruction, and determining the logical page number according to the logical address.
[0052] In one practicable manner, in step 103, the business data and transaction tag value of the data in the memory are modified according to the data update instruction to obtain the updated data, specifically:
[0053] Determine whether the current update is the last update according to the data update instruction. If so, modify the business data of the data in the memory according to the data update instruction, and change the transaction mark value from the third preset value to the fourth preset value to obtain the updated data. Otherwise, modify the business data of the data in the memory according to the data update instruction to obtain the updated data.
[0054] In one practicable manner, in step 104, the business data and transaction tag value of the data in the memory are modified according to the data update instruction to obtain the updated data, specifically:
[0055] Determine whether the current update is the last update according to the data update instruction. If so, modify the business data of the data in the memory according to the data update instruction, and modify the transaction mark value from the second preset value to the fourth preset value to obtain the updated data. Otherwise, modify the business data of the data in the memory according to the data update instruction, and modify the transaction mark value from the second preset value to the third preset value to obtain the updated data.
[0056] An implementable method, after obtaining a free page corresponding to the first physical address in the free area address mapping table, before writing the updated data into the obtained free page to obtain a transaction page, also includes: determining whether the obtained free page is a bad page, if so, subtracting preset data from the number of valid free pages, and ending; otherwise, writing the updated data in the memory into the obtained free page according to the storage format of the data page to be updated to obtain a transaction page.
[0057] Specifically, determining whether the obtained free page is a bad page is as follows:
[0058] Step D1, write the preset byte data into the idle page, read the data in the idle page, and determine whether the written data is consistent with the read data. If they are consistent, it is determined that it is not a bad page. If they are inconsistent, execute step D2;
[0059] Step D2, obtain the corresponding bad page identification page according to the free page physical address, mark the number of errors in the bad page identification page in a predetermined manner, and determine whether the number of errors in the bad page identification page reaches a preset number of errors. If so, determine it as a bad page, otherwise execute step D1.
[0060] An implementable method, before obtaining a free page corresponding to the first physical address in the free area address mapping table, also includes: determining whether the number of current valid free pages in the free area is less than the minimum number of valid free pages, if so, reporting an error and ending, otherwise obtaining a free page corresponding to the first physical address in the free area address mapping table.
[0061] A data storage method provided by the present invention initializes the user area, manages the original data page and the transaction page through the mark in the data formatting during the original data update process according to the update data instruction, so that the user data page, the idle page and the transaction page size can be flexibly configured, the stability and service life of the system are improved through the bad page management mechanism, and the integrity of multiple pages of data during the modification process is guaranteed by modifying the transaction mark and the structured mark.
[0062] Embodiment 2
[0063] Embodiment 2 of the present invention provides a data storage method, which includes a user area data mapping table construction process and a user area data update process; wherein the data mapping table includes a data area address mapping table and a free area address mapping table;
[0064] like Figure 2 As shown, the process of constructing a data mapping table in the user area in the data storage method includes:
[0065] Step 201: Power on the chip and obtain an initialization completion mark;
[0066] In this embodiment, the initialization completion mark is stored in the user area. If the chip is powered on for the first time, the user area needs to be initialized to structure the data area space, so as to facilitate the establishment of a mapping relationship table of data in the data area.
[0067] Step 202, judging whether the user area has completed initialization according to the initialization completion mark, if yes, executing step 204, if no, executing step 203;
[0068] In one practicable manner, judging whether initialization is completed according to the initialization completion mark is as follows: judging whether the value of the initialization completion mark is a first preset value, if so, determining that initialization is completed, otherwise determining that initialization is not completed.
[0069] Specifically, the first preset value is 01;
[0070] Step 203, initializing the user area, and after completing the initialization process, modifying the initialization completion mark value to a first preset value, and then ending;
[0071] An implementable method for initializing the user area specifically includes:
[0072] Step A1, setting the maximum number of data pages that can be stored in the data area, the number of valid free pages in the free area, and the minimum number of valid free pages in the free area;
[0073] In this embodiment, the number of data pages and the number of free pages are set according to user needs. The number of data pages cannot be changed after being set. The number of free pages will decrease with the increase in the frequency of use. The minimum number of valid free pages in the free area is to ensure that the transaction can be completed smoothly. Assume that the minimum number of valid free pages in the free area is set to 3, the current update transaction requires 3 free pages, and there are 2 valid free pages remaining during the current update transaction, then the current update transaction will fail.
[0074] Step A2, formatting the data pages in the data area, and setting the free pages in the free area;
[0075] In an implementable manner, formatting the data pages in the data area specifically includes: performing structural setting on each data page in the data area according to preset bytes, the structural setting specifically includes setting the service data length, the logical page number, the transaction mark, and the structural mark. Specifically, a logical page number and a physical address are assigned to each data page, the transaction mark of each data page is set to a second preset value, and the structural mark of each data page is set to a fifth preset value;
[0076] For example, the second preset value is 00, and the fifth preset value is 5A;
[0077] For example, the space size of a data page is 512 bytes, of which 509 bytes are the service data length and 3 bytes are auxiliary data. The structure of the data page is as follows:
[0078]
[0079] For example, assuming that the starting physical address of the user area is 008000, the available storage space of the data area is 32K, and the maximum number of data pages set in the data area is 64 pages, the structure after formatting the data pages in the data area is as follows:
[0080]
[0081] In an practicable manner, setting the free pages in the free area specifically includes: allocating a physical address to each free page in the free area;
[0082] For example, assuming that the user area physical address starts at 0x8000, the data area can store 32K of space, the free area can store 32K of space, and the maximum number of free pages set in the free area is 64 pages. The structure after initializing the free pages in the free area is as follows:
[0083]
[0084] Step A3: constructing a data area address mapping table and a free area address mapping table;
[0085] In an practicable manner, constructing the data area address mapping table and the idle area address mapping table specifically comprises: constructing a mapping relationship table of physical addresses and logical page numbers in the data area, and constructing a mapping relationship table of physical addresses in the idle area;
[0086] Specifically, the mapping relationship table between physical addresses and logical pages in the data area is the data area address mapping table DataMap, and the data representation in DataMap is <logical page number, physical address>; the mapping relationship table between physical addresses and sequences in the idle area is the idle area address mapping table idleMap, and the data representation in idleMap is <sequence, physical address>.
[0087] In this embodiment, after step 203, the process further includes waiting for receiving a user area data update instruction, and executing the user area data update process when the data update instruction is received.
[0088] Step 204, scan and obtain the physical page in the user area, determine whether the obtained physical page is a bad page, if yes, subtract the preset data from the number of valid free pages, and continue to obtain the next physical page, otherwise, construct a physical page mapping relationship according to the scanning result and store it in the free area address mapping table, the data area address mapping table or the update data table;
[0089] Specifically, the preset data is 1;
[0090] In this embodiment, scanning and acquiring the physical pages in the user area specifically includes: scanning and acquiring the physical pages in a preset order;
[0091] Furthermore, scanning and acquiring the physical pages in a preset order specifically includes: acquiring the physical pages in a corresponding physical address order of the physical pages;
[0092] In an implementable manner, initializing the user area further comprises constructing an update data table and a data backup table, wherein the update data table and the data backup table are empty during initialization;
[0093] Specifically, constructing a physical page mapping relationship according to the scan result and storing it in a free area address mapping table, a data area address mapping table or an update data table specifically includes:
[0094] Step B1, determining whether the structured tag value in the physical page is a fifth preset value, if yes, obtaining the transaction tag value in the physical page, and executing step B2, otherwise treating the physical page as an idle page, and storing the physical address corresponding to the physical page in the idle area address mapping table;
[0095] The storing of the physical address corresponding to the physical page into the free area address mapping table specifically includes: storing the physical address of the physical page into the free area address mapping table in sequence according to a predetermined format;
[0096] Further, the predetermined format is in the form of a key-value pair, for example, <sequence, physical address>;
[0097] Step B2, determine whether the transaction mark value in the physical page is a second preset value. If so, treat the physical page as a data page, and store the physical address of the physical page and the logical page number as a mapping relationship in the data area address mapping table; otherwise, treat the physical page as a transaction page, and store the physical address of the physical page and the logical page number as a mapping relationship in the update data table.
[0098] The transaction mark value further includes a third preset value and a fourth preset value, for example, the second preset value is 00, the third preset value is 77, and the fourth preset value is AA;
[0099] In this embodiment, if the transaction mark value is the third preset value or the fourth preset value, it means that an abnormal situation occurs when updating the data. At this time, the physical page whose transaction mark value is the third preset value or the fourth preset value is the transaction page generated during the update. It is necessary to determine whether to continue to complete the update operation according to the mark state of the transaction page. Therefore, it is necessary to store the information of the physical page whose transaction mark value is the third preset value or the fourth preset value in the update data table.
[0100] Further, storing the physical address of the physical page and the logical page number as a mapping relationship in the data area address mapping table is specifically as follows: obtaining the logical page number and the physical address of the physical page, and storing the logical page number and the physical address in the data area address mapping table according to a preset format;
[0101] The default format is a key-value pair, such as <logical page number, physical address>;
[0102] Furthermore, storing the physical address of the physical page and the logical page number as a mapping relationship in the update data table specifically includes: obtaining the logical page number and the physical address of the physical page, and storing the logical page number and the physical address in the update data table according to a preset format;
[0103] The default format is a key-value pair, such as <logical page number, physical address>;
[0104] Step 205: After all physical pages are scanned, determine whether there is a physical page mapping relationship in the update data table. If yes, execute step 206; otherwise, end;
[0105] In this embodiment, if there is no physical page mapping relationship in the update data table, it means that there is no abnormality in the physical page in the user area, and the data area address mapping table and the free area address mapping table are constructed.
[0106] In this embodiment, when it is determined in step 205 that there is no physical page mapping relationship in the update data table, the process further includes: waiting to receive a user area data update instruction, and executing a user area data update process when the update instruction is received.
[0107] Step 206: Update the free area address mapping table and the data area address mapping table according to the physical page mapping relationship in the update data table;
[0108] In this embodiment, after step 206, the process further includes: waiting to receive a user area data update instruction, and executing a user area data update process when the update instruction is received.
[0109] In this embodiment, step 206 specifically includes:
[0110] Step C1, obtaining a physical page according to the logical page number in the physical page mapping relationship in the update data table;
[0111] Step C2, determining whether there is a physical page with a transaction mark value equal to a fourth preset value in the acquired physical pages, if so, executing step C3, otherwise executing step C4;
[0112] Among them, the fourth preset value is AA;
[0113] Step C3, modifying the structured mark values of all physical pages in the data area address mapping table that have the same logical page number as that in the update data table to the sixth preset value, modifying the transaction mark values of all physical pages corresponding to the physical addresses in the update data table to the second preset value, storing the physical addresses in the data area address mapping table that correspond to the logical page numbers in the update data table to the free area address mapping table, storing the physical page mapping relationship in the update data table to the data area address mapping table, and clearing the update data table;
[0114] In one practicable manner, step C3 specifically includes:
[0115] Step C31, according to the logical page number in the update data table, search all corresponding physical page mapping relationships from the data area address mapping table and store them in the data backup table;
[0116] Specifically, storing the physical page mapping relationship in the data backup table specifically includes: storing the logical page number and the physical address of the physical page in the data backup table according to a predetermined format;
[0117] Further, the predetermined format is in the form of a key-value pair, for example, <logical page number, physical address>;
[0118] Step C32, modifying the structured tag values of all physical pages corresponding to the physical addresses in the data backup table to the sixth preset value, modifying the transaction tag values of all physical pages corresponding to the physical addresses in the update data table to the second preset value, storing the physical addresses in the data area address mapping table corresponding to the logical page numbers in the update data table to the free area address mapping table, storing the physical page mapping relationship in the update data table to the data area address mapping table, and clearing the update data table and the backup data table;
[0119] Specifically, the structured mark value of the physical page corresponding to the physical address in the data backup table is 5A, which is modified to the sixth preset value 00;
[0120] Specifically, the transaction mark value of the physical page corresponding to the physical address in the update data table is AA / 77, which is modified to the second preset value of 00;
[0121] Specifically, the physical address corresponding to the logical page number in the update data table in the data area address mapping table is stored in the free area address mapping table, and the physical page mapping relationship in the update data table is stored in the data area address mapping table. Specifically, the mapping relationship that is the same as the mapping relationship in the data backup table is found from the data area address mapping table, and the physical address in the found mapping relationship is modified to the physical address in the mapping relationship in the update data table according to the corresponding logical page number, and the physical address that is the same as the physical address in the update data table is found from the free area address mapping table, and the found physical address is modified to the physical address in the mapping relationship in the data backup table;
[0122] In this embodiment, after step C3, the method further includes: waiting to receive a user area data update instruction, and executing a user area data update process when the update instruction is received;
[0123] Step C4: modify the structured identifiers of all physical pages corresponding to the physical addresses in the update data table to the sixth preset value, and store the physical addresses in the update data table into the free area address mapping table.
[0124] The storing of the physical address in the update data table into the free area address mapping table specifically includes: storing the physical address into the free area address mapping table in a preset format sequence;
[0125] Among them, the sixth preset value is 00;
[0126] In this embodiment, after step C4, the process further includes waiting for receiving a user area data update instruction, and executing a user area data update process after receiving the update instruction.
[0127] In this embodiment, user area data can be updated in a variety of ways. A transaction update can be completed through one instruction or multiple instructions. An update instruction can include one or more updates to a data page, or it can include updates to multiple data pages. The solution provided in this embodiment can implement all of the above update methods.
[0128] like Figure 3 As shown, the user area data update process in the data storage method includes:
[0129] Step 301: determine the logical page number according to the data update instruction, and obtain the physical address from the data area address mapping table according to the logical page number;
[0130] In this embodiment, determining the logical page number according to the data update instruction specifically includes: acquiring the logical address in the data update instruction, and determining the logical page number according to the logical address;
[0131] In this embodiment, the data update instruction may include multiple logical addresses;
[0132] Step 301 also includes: determining whether there are multiple acquired logical addresses, if yes, acquiring the first logical address in the logical addresses and executing step 302, otherwise executing step 302;
[0133] For example, the length of the business data in the set data page is 509 (0x01FD) bytes, and the data update instruction is: 00D63125025566, where 0x3125 in the data update instruction is the logical address, 02 indicates the length of the byte data to be modified, and 5566 indicates the new data. The logical page number and the starting address of the data to be modified in the physical page corresponding to the logical page number are calculated according to the logical address and the length of the business data in the data page;
[0134] For example, the logical page number = 0x3125 / 0x01FD=0x18=24 (decimal logical page number), the page offset = 0x3125%0x01FD=0x016D (the starting address of the modified data in the page);
[0135] Step 302: Obtain the data page to be updated according to the physical address;
[0136] Step 303, determine whether there is a transaction page corresponding to the data page to be updated according to the logical page number, if yes, execute step 304, otherwise execute step 307;
[0137] In an practicable manner, it is determined according to the logical page number whether there is a transaction page corresponding to the data page to be updated in the update data table, if so, step 304 is executed, otherwise, step 307 is executed;
[0138] Step 304: Obtain the transaction page corresponding to the data page to be updated according to the logical page number, copy the data of the transaction page to the memory, modify the business data and transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, erase the data in the acquired transaction page and write the updated data in the memory to the transaction page, and execute step 305;
[0139] In this embodiment, obtaining the transaction page corresponding to the to-be-updated data page according to the logical page number specifically includes: obtaining, according to the logical page number, a physical page corresponding to a transaction mark value having a third preset value as the transaction page corresponding to the to-be-updated data page;
[0140] In one practicable manner, obtaining the transaction page corresponding to the data page to be updated according to the logical page number is specifically as follows: obtaining the physical address corresponding to the logical page number from the update data table according to the logical page number, and obtaining the transaction page corresponding to the data page to be updated through the physical address;
[0141] In an practicable manner, before step 304, the method further includes: determining whether the current update is the last update according to the data update instruction, and if so, modifying the business data and the transaction mark value of the data in the memory according to the instruction to obtain the updated data, specifically: modifying the business data of the data in the memory according to the data update instruction, and modifying the transaction mark value from the third preset value to the fourth preset value to obtain the updated data, otherwise, modifying the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, specifically: modifying the business data of the data in the memory according to the data update instruction to obtain the updated data;
[0142] Specifically, determining whether the current update is the last update specifically includes: determining whether it is the last update according to a preset field in the data update instruction;
[0143] For example, the data update instruction is 00D63125025566, where 00 indicates that the instruction is an intermediate instruction and not the last update, and the data update instruction is 81D63125025566, where 81 indicates that the instruction is the last update.
[0144] Step 305, determine whether the update transaction is completed, if yes, execute step 306, otherwise execute step 301;
[0145] In an practicable manner, determining whether the update transaction is finished is specifically as follows: determining whether the transaction mark value in the transaction page is a fourth preset value, if so, determining that the update transaction is finished, otherwise determining that the update transaction is not finished;
[0146] In this embodiment, determining that the update transaction is not completed further includes: returning an update response and executing step 301 .
[0147] Step 306: modify the structured mark values of all data pages to be updated to the sixth preset value, modify the transaction mark values of all transaction pages to the second preset value, use all transaction pages as updated data pages, update the data area address mapping table according to the physical addresses of the updated data pages, and update the free area address mapping table according to the physical addresses of all data pages to be updated, and end;
[0148] An implementable manner is to update the data area address mapping table according to the physical address of the updated data page, and to update the idle area address mapping table according to the physical addresses of all data pages to be updated, specifically: update the data area address mapping table and the idle area address mapping table according to the updated data table and the data backup table;
[0149] An implementable manner of updating the data area address mapping table and the free area address mapping table according to the updated data table and the data backup table is as follows: finding a mapping relationship identical to the mapping relationship in the data backup table from the data area address mapping table, modifying the physical address in the found mapping relationship to the physical address in the mapping relationship in the updated data table according to the corresponding logical page number, finding a physical address identical to the physical address in the updated data table from the free area address mapping table, and modifying the found physical address to the physical address in the mapping relationship in the data backup table;
[0150] Specifically, step 306 also includes clearing the update data table and the data backup table.
[0151] Step 307: copy the data of the data page to be updated to the memory, modify the business data and transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, obtain the free page corresponding to the first physical address in the free area address mapping table, write the updated data in the memory into the obtained free page according to the storage format of the data page to be updated to obtain the transaction page, and execute step 308;
[0152] In an practicable manner, before executing step 307, the method further includes: storing the logical page number and the physical address corresponding to the free page in the update data table according to a predetermined format, and storing the logical page number and the physical address corresponding to the data page to be updated in the data backup table according to a predetermined format;
[0153] In an practicable manner, before step 307, it further includes: determining whether the current update is the last update according to the data update instruction, if so, modifying the business data and the transaction mark value of the data in the memory according to the data update instruction in step 307 to obtain the updated data specifically includes: modifying the business data of the data in the memory according to the data update instruction, and modifying the transaction mark value from the second preset value to the fourth preset value to obtain the updated data; otherwise, modifying the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data specifically includes: modifying the business data of the data in the memory according to the data update instruction, and modifying the transaction mark value from the second preset value to the third preset value to obtain the updated data;
[0154] For example, copy the data page with the logical page number 24 to the memory, and modify the two bytes of data starting from the offset address 0x016D in the page to 5566;
[0155] Specifically, determining whether the current update is the last update includes: determining whether it is the last update according to a preset field in the data update instruction.
[0156] Further, the second preset value is 00, the third preset value is 77, and the fourth preset value is AA;
[0157] In an practicable manner, obtaining a free page corresponding to the first physical address in the free area address mapping table is specifically as follows: obtaining the physical address in the first mapping relationship from the free area address mapping table, and obtaining a free page corresponding to the physical address;
[0158] In an practicable manner, after obtaining a free page corresponding to the first physical address in the free area address mapping table, before writing the updated data in the memory into the obtained free page according to the storage format of the data page to be updated to obtain the transaction page, it also includes: determining whether the obtained free page is a bad page, if so, subtracting a preset data from the number of valid free pages, and ending; otherwise, writing the updated data in the memory into the obtained free page according to the storage format of the data page to be updated to obtain the transaction page;
[0159] Specifically, determining whether the obtained free page is a bad page is as follows:
[0160] Step D1, write the preset byte data into the idle page, read the data in the idle page, and determine whether the written data is consistent with the read data. If they are consistent, it is determined that it is not a bad page. If they are inconsistent, execute step D2;
[0161] Step D2, obtaining the corresponding bad page identification page in the FLASH storage area according to the free page physical address, marking the number of errors in the bad page identification page according to a predetermined method, and determining whether the number of errors in the bad page identification page reaches a preset number of errors, if so, determining it as a bad page, otherwise executing step D1;
[0162] In an practicable manner, when determining that the obtained free page is a bad page, the method further includes: returning an update data exception, powering off and then powering on again.
[0163] An implementable method, before obtaining a free page corresponding to the first physical address in the free area address mapping table, also includes: determining whether the number of current valid free pages in the free area is less than the minimum number of valid free pages, if so, reporting an error and ending, otherwise obtaining a free page corresponding to the first physical address in the free area address mapping table.
[0164] Step 308, determine whether the update transaction is completed, if yes, execute step 309, otherwise execute step 301;
[0165] In an practicable manner, determining whether the update transaction is finished is specifically as follows: determining whether the transaction mark value in the transaction page is a fourth preset value, if so, determining that the update transaction is finished, otherwise determining that the update transaction is not finished;
[0166] In this embodiment, determining that the update transaction is not completed further includes: returning an update response and executing step 301 .
[0167] Step 309: modify the structured mark value of the data page to be updated to the sixth preset value, modify the transaction mark value in the transaction page to the second preset value, use all transaction pages as updated data pages, update the data area address mapping table according to the physical addresses of the updated data pages, and update the free area address mapping table according to the physical addresses of all data pages to be updated, and end;
[0168] An implementable manner is to update the data area address mapping table according to the physical address of the updated data page, and to update the idle area address mapping table according to the physical addresses of all data pages to be updated, specifically: update the data area address mapping table and the idle area address mapping table according to the updated data table and the data backup table;
[0169] An implementable manner of updating the data area address mapping table and the free area address mapping table according to the updated data table and the data backup table is as follows: finding a mapping relationship identical to the mapping relationship in the data backup table from the data area address mapping table, modifying the physical address in the found mapping relationship to the physical address in the mapping relationship in the updated data table according to the corresponding logical page number, finding a physical address identical to the physical address in the updated data table from the free area address mapping table, and modifying the found physical address to the physical address in the mapping relationship in the data backup table;
[0170] Specifically, step 309 also includes clearing the update data table and the data backup table.
[0171] A data storage method provided by the present invention performs initialization on a user area, manages original data pages and transaction pages through marks in data formatting during the original data update process according to an update data instruction, thereby flexibly configuring the size of user data pages, free pages and transaction pages, having a bad page management mechanism, improving the stability and service life of the system, and realizing the modification integrity of multi-page data during the modification process by adjusting transaction marks and structured marks.
[0172] The following are embodiments of the apparatus of the present invention, which can be used to implement the embodiments of the method of the present invention. For details not disclosed in the embodiments of the apparatus of the present invention, reference can be made to the embodiments of the method of the present invention.
[0173] An exemplary embodiment of the present invention provides a data storage device, the device comprising:
[0174] A first judging module is used to judge whether the user area is initialized, and if it is judged that the initialization is completed, the first updating module is triggered; if it is judged that the initialization is not completed, the initialization module is triggered;
[0175] The initialization module is used to perform initialization processing on the user area, and the initialization processing specifically includes constructing a data area address mapping table and a free area address mapping table, waiting to receive a data update instruction, and triggering the first determination module when receiving the data update instruction;
[0176] The first updating module is used to scan the user area, update the data area address mapping table and the free area address mapping table according to the scanning result, wait for receiving the data update instruction, and trigger the first determining module when receiving the data update instruction;
[0177] A first determination module is used to determine the logical page number according to the data update instruction, obtain the physical address corresponding to the logical page number from the data area address mapping table, obtain the data page to be updated according to the physical address, and determine whether there is a transaction page corresponding to the data page to be updated according to the logical page number, and trigger the second update module if it is determined that it exists, and trigger the third update module if it is determined that it does not exist;
[0178] The second update module is used to obtain the transaction page corresponding to the data page to be updated according to the logical page number, copy the data of the transaction page to the memory, modify the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, write the updated data into the transaction page corresponding to the data page to be updated, determine whether the update transaction is completed, if it is determined that the update transaction is completed, trigger the fourth update module, if it is determined that the update transaction is not completed, trigger the first determination module;
[0179] The third update module is used to copy the data of the data page to be updated to the memory, modify the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, obtain a free page corresponding to the first physical address in the free area address mapping table, write the updated data into the obtained free page to obtain the transaction page, determine whether the current update transaction is completed, and if it is determined that the current update transaction is completed, trigger the fourth update module, and if it is determined that the current update transaction is not completed, trigger the second determination module;
[0180] The fourth update module is used to modify the structured mark values of all data pages to be updated to the sixth preset value, modify the transaction mark values of all transaction pages to the second preset value, use all transaction pages as updated data pages, update the data area address mapping table according to the physical addresses of the updated data pages, and update the free area address mapping table according to the physical addresses of all data pages to be updated.
[0181] In an implementable manner, the user area includes a data area and a free area, the initialization module is specifically used to format the data pages in the data area and assign physical addresses, assign physical addresses to the free pages in the free area, and construct a data area address mapping table and a free area address mapping table according to the assigned physical addresses.
[0182] In an implementable manner, the first update module is specifically used to construct a physical page mapping relationship based on the scanning results and store it in a free area address mapping table, a data area address mapping table or an update data table, and determine whether there is a physical page mapping relationship in the update data table. If so, the free area address mapping table and the data area address mapping table are updated according to the physical page mapping relationship in the update data table, otherwise the update module ends.
[0183] Specifically, when the first update module is used to construct a physical page mapping relationship according to the scanning result and store it in a free area address mapping table, a data area address mapping table or an update data table, the first update module includes:
[0184] A first judgment submodule is used to judge whether the structured tag value in the scanned physical page is a fifth preset value, and if so, obtain the transaction tag value in the physical page to trigger the second judgment submodule; otherwise, the physical page is regarded as an idle page, and the physical address corresponding to the physical page is stored in the idle area address mapping table;
[0185] The second judgment submodule is used to judge whether the transaction mark value in the physical page is a second preset value. If so, the physical page is used as a data page, and the physical address of the physical page and the logical page number are stored as a mapping relationship in the data area address mapping table; otherwise, the physical page is used as a transaction page, and the physical address of the physical page and the logical page number are stored as a mapping relationship in the update data table.
[0186] Specifically, the first updated mold block includes:
[0187] A first acquisition unit is used to acquire a physical page according to a logical page number in a physical page mapping relationship in an update data table;
[0188] a first judging unit, configured to judge whether there is a physical page whose transaction mark value is a fourth preset value in the acquired physical pages, and trigger the first updating unit if it is judged that there is a physical page whose transaction mark value is a fourth preset value, and trigger the second updating unit if it is judged that there is a physical page whose transaction mark value is a fourth preset value;
[0189] A first updating unit is used to modify the structured mark values of all physical pages in the data area address mapping table that have the same logical page number as that in the update data table to a sixth preset value, modify the transaction mark values of all physical pages corresponding to the physical addresses in the update data table to a second preset value, store the physical addresses in the data area address mapping table that correspond to the logical page numbers in the update data table to the free area address mapping table, store the physical page mapping relationship in the update data table to the data area address mapping table, and clear the update data table;
[0190] The second updating unit is used to modify the structured identifiers of all physical pages corresponding to the physical addresses in the update data table to a sixth preset value, store the physical addresses corresponding to the physical pages in the update data table into the free area address mapping table, and clear the update data table.
[0191] In an implementable manner, when determining the logical page number according to the data update instruction, the first determination module is specifically used to obtain the logical address in the data update instruction, and determine the logical page number according to the logical address.
[0192] In an implementable manner, the second update module is used to modify the business data and transaction mark value of the transaction page in the memory according to the data update instruction to obtain updated data. The second update module is specifically used to determine whether the current update is the last update according to the data update instruction. If so, the original business data of the transaction page in the memory is modified according to the data update instruction to obtain modified data, and the transaction mark value is modified from a third preset value to a fourth preset value to obtain updated data. Otherwise, the original business data of the transaction page in the memory is modified according to the data update instruction to obtain updated data.
[0193] In an implementable manner, the third update module is used to modify the business data and transaction mark value of the transaction page in the memory according to the data update instruction to obtain updated data, and the second update module is specifically used to determine whether the current update is the last update according to the data update instruction. If so, the original business data of the data page to be updated in the memory is modified according to the data update instruction to obtain modified data, and the transaction mark value is modified from the second preset value to the fourth preset value to obtain updated data; otherwise, the original business data of the data page to be updated in the memory is modified according to the data update instruction to obtain modified data, and the transaction mark value is modified from the second preset value to the third preset value to obtain updated data.
[0194] In an implementable manner, the third update module is also used to determine whether the obtained free page is a bad page. If so, the number of valid free pages is subtracted from the preset data and the process ends. Otherwise, the updated data in the memory is written into the obtained free page according to the storage format of the data page to be updated to obtain a transaction page.
[0195] Specifically, the third update module is used to determine whether the obtained free page is a bad page through the first determination submodule, and is specifically used to write preset byte data into the free page, read the data in the free page, and determine whether the written data is consistent with the read data. If they are consistent, it is determined that it is not a bad page. If they are inconsistent, the corresponding bad page identification page is obtained according to the physical address of the free page, and the number of errors is marked in the bad page identification page in a predetermined manner. It is judged whether the number of errors in the bad page identification page reaches the preset number of errors. If so, it is determined to be a bad page. Otherwise, the first determination module is triggered.
[0196] In an implementable manner, the third update module is also used to determine whether the number of current valid free pages in the free area is less than the minimum number of valid free pages. If so, an error is reported and the process ends; otherwise, a free page corresponding to the first physical address in the free area address mapping table is obtained.
[0197] It should be noted that the data storage device provided in the above embodiment only uses the division of the above functional modules as an example when executing the storage method. In actual applications, the above functions can be allocated and completed by different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the data storage device provided in the above embodiment and the data storage method embodiment belong to the same concept, and the implementation process thereof is specifically shown in the method embodiment, which will not be repeated here.
[0198] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0199] An embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of any of the aforementioned method embodiments.
[0200] The embodiment of the present invention further provides a computer-readable storage medium on which a computer program / instruction is stored, and when the program / instruction is executed by a processor, the steps of the method of any of the above embodiments are implemented. The computer-readable storage medium may include, but is not limited to, any type of disk, including a floppy disk, an optical disk, a DVD, a CD-ROM, a micro drive, and a magneto-optical disk, a ROM, a RAM, an EPROM, an EEPROM, a DRAM, a VRAM, a flash memory device, a magnetic card or an optical card, a nanosystem (including a molecular memory IC), or any type of medium or device suitable for storing instructions and / or data.
[0201] An embodiment of the present invention provides a computer program product, including a computer program / instruction, wherein the computer program / instruction, when executed by a processor, implements the steps of any of the methods of the aforementioned embodiments.
[0202] In the present invention, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or order; the term "plurality" refers to two or more, unless otherwise clearly defined. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone. The character " / " generally indicates that the objects associated with each other are in an "or" relationship. Terms such as "install", "connect", "connect", and "fix" should be understood in a broad sense. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection; "connection" can be a direct connection or an indirect connection through an intermediate medium. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0203] In the description of the present invention, it is necessary to understand that the directions or positional relationships indicated by the terms "upper" and "lower" etc. are based on the directions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or unit referred to must have a specific direction, be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation on the present invention.
[0204] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope covered by the present invention.
Claims
1. A data storage method, characterized in that: The method comprises: Step S1, power on the chip, determine whether the user area has been initialized, if yes, scan the user area, update the data area address mapping table and the idle area address mapping table according to the scanning result, wait for receiving the data update instruction, and execute step S2 when receiving the data update instruction; if no, initialize the user area, wait for receiving the data update instruction, and execute step S2 when receiving the data update instruction, and the initialization process specifically includes constructing the data area address mapping table and the idle area address mapping table; Step S2, determining the logical page number according to the data update instruction, obtaining the physical address corresponding to the logical page number from the data area address mapping table, obtaining the data page to be updated according to the physical address, and determining whether there is a transaction page corresponding to the data page to be updated according to the logical page number, if yes, executing step S3, otherwise executing step S4; Step S3, obtaining the transaction page corresponding to the data page to be updated according to the logical page number, copying the data of the obtained transaction page to the memory, modifying the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, writing the updated data into the transaction page corresponding to the data page to be updated, and determining whether the update transaction is completed. If so, executing step S5; otherwise, waiting to receive the data update instruction, executing step S2 when receiving the data update instruction or directly executing step S2; Step S4, copy the data of the data page to be updated to the memory, modify the business data and transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, obtain an idle page corresponding to the first physical address in the idle area address mapping table, write the updated data into the obtained idle page to obtain the transaction page, determine whether the update transaction is completed, if so, execute step S5, if not, wait to receive the data update instruction, and execute step S2 when the data update instruction is received, or directly execute step S2; Step S5, modify the structured mark value of all data pages to be updated to the sixth preset value, modify the transaction mark value of all transaction pages to the second preset value, use all transaction pages as updated data pages, update the data area address mapping table according to the physical address of the updated data page, update the free area address mapping table according to the physical address of all data pages to be updated, and end.
2. The data storage method according to claim 1, characterized in that: The user area includes a data area and a free area, and the initialization process of the user area specifically includes: Step A1, formatting and assigning physical addresses to data pages in the data area, and assigning physical addresses to idle pages in the idle area; Step A2: construct the data area address mapping table and the free area address mapping table according to the allocated physical addresses.
3. The data storage method according to claim 1, characterized in that: The updating of the data area address mapping table and the free area address mapping table according to the scanning result specifically includes: Constructing a physical page mapping relationship according to the scanning result and storing it in the free area address mapping table, the data area address mapping table or the update data table; Determine whether there is a physical page mapping relationship in the update data table, if yes, update the free area address mapping table and the data area address mapping table according to the physical page mapping relationship in the update data table, otherwise end.
4. The data storage method according to claim 3, characterized in that: The step of constructing a physical page mapping relationship according to the scanning result and storing it in the free area address mapping table, the data area address mapping table or the update data table specifically includes: Step B1, determining whether the structured tag value in the scanned physical page is a fifth preset value, if yes, obtaining the transaction tag value in the physical page, and executing step B2, otherwise treating the physical page as an idle page, and storing the physical address corresponding to the physical page in the idle area address mapping table; Step B2, determine whether the transaction mark value in the physical page is a second preset value. If so, use the physical page as a data page, and store the physical address of the physical page and the logical page number as a mapping relationship in the data area address mapping table; otherwise, use the physical page as a transaction page, and store the physical address of the physical page and the logical page number as a mapping relationship in the update data table.
5. The data storage method according to claim 3, characterized in that: The updating of the free area address mapping table and the data area address mapping table according to the physical page mapping relationship in the update data table specifically includes: Step C1, obtaining a physical page according to the logical page number in the physical page mapping relationship in the update data table, and determining whether there is a physical page with a transaction mark value of a fourth preset value in the obtained physical page, if yes, executing step C2, otherwise executing step C3; Step C2, modifying the structured mark values of all physical pages in the data area address mapping table that have the same logical page number as that in the update data table to a sixth preset value, modifying the transaction mark values of all physical pages corresponding to the physical addresses in the update data table to a second preset value, storing the physical addresses in the data area address mapping table that correspond to the logical page numbers in the update data table to the free area address mapping table, storing the physical page mapping relationship in the update data table to the data area address mapping table, and clearing the update data table; Step C3: modify the structured identifiers of all physical pages corresponding to the physical addresses in the update data table to a sixth preset value, store the physical addresses in the update data table into the free area address mapping table, and clear the update data table.
6. The data storage method according to claim 1, characterized in that: The determining of the logical page number according to the data update instruction specifically includes: obtaining a logical address in the data update instruction, and determining the logical page number according to the obtained logical address.
7. The data storage method according to claim 1, characterized in that: In step S3, the business data and transaction mark value of the data in the memory are modified according to the data update instruction to obtain the updated data, specifically: Determine whether the current update is the last update according to the data update instruction. If so, modify the business data of the data in the memory according to the data update instruction, and modify the transaction mark value from the third preset value to the fourth preset value to obtain the updated data. Otherwise, modify the business data of the data in the memory according to the data update instruction to obtain the updated data.
8. The data storage method according to claim 1, characterized in that: In step S4, the business data and transaction mark value of the data in the memory are modified according to the data update instruction to obtain the updated data, specifically: Determine whether the current update is the last update according to the data update instruction; if so, modify the business data of the data in the memory according to the data update instruction, and modify the transaction mark value from the second preset value to the fourth preset value to obtain the updated data; otherwise, modify the business data of the data in the memory according to the data update instruction, and modify the transaction mark value from the second preset value to the third preset value to obtain the updated data.
9. The data storage method according to claim 1, characterized in that: After obtaining an idle page corresponding to the first physical address in the idle area address mapping table, before writing the updated data into the obtained idle page to obtain the transaction page, it also includes: determining whether the obtained idle page is a bad page, if so, subtracting preset data from the number of valid idle pages, and ending; otherwise, writing the updated data in the memory into the obtained idle page according to the storage format of the data page to be updated to obtain a transaction page.
10. The data storage method according to claim 9, characterized in that: The method of determining whether the obtained free page is a bad page is specifically as follows: Step D1, write the preset byte data into the idle page, read the data in the idle page, and determine whether the written data is consistent with the read data. If they are consistent, it is determined that it is not a bad page. If they are inconsistent, execute step D2; Step D2, obtain the corresponding bad page identification page according to the free page physical address, mark the number of errors in the bad page identification page in a predetermined manner, and determine whether the number of errors in the bad page identification page reaches a preset number of errors. If yes, determine it as a bad page, otherwise execute step D1.
11. The data storage method according to claim 1, characterized in that: Before obtaining a free page corresponding to the first physical address in the free area address mapping table, the method also includes: determining whether the number of current valid free pages in the free area is less than the minimum number of valid free pages, if so, reporting an error and ending, otherwise obtaining a free page corresponding to the first physical address in the free area address mapping table.
12. A data storage device, characterized in that: The device comprises: A first judging module is used to judge whether the user area is initialized, and if it is judged that the initialization is completed, the first updating module is triggered; if it is judged that the initialization is not completed, the initialization module is triggered; The initialization module is used to perform initialization processing on the user area, and the initialization processing specifically includes constructing a data area address mapping table and a free area address mapping table, waiting to receive a data update instruction, and triggering the first determination module when receiving the data update instruction; The first updating module is used to scan the user area, update the data area address mapping table and the free area address mapping table according to the scanning result, wait for receiving the data update instruction, and trigger the first determining module when receiving the data update instruction; The first determination module is used to determine the logical page number according to the data update instruction, obtain the physical address corresponding to the logical page number from the data area address mapping table, obtain the data page to be updated according to the physical address, and determine whether there is a transaction page corresponding to the data page to be updated according to the logical page number, and trigger the second update module if it is determined that it exists, and trigger the third update module if it is determined that it does not exist; The second update module is used to obtain the transaction page corresponding to the data page to be updated according to the logical page number, copy the data of the obtained transaction page to the memory, modify the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, write the updated data into the transaction page corresponding to the data page to be updated, determine whether the current update transaction is completed, if it is determined that the current update transaction is completed, trigger the fourth update module, if it is determined that the current update transaction is not completed, trigger the first determination module; The third update module is used to copy the data of the data page to be updated to the memory, modify the business data and the transaction mark value of the data in the memory according to the data update instruction to obtain the updated data, obtain a free page corresponding to the first physical address in the free area address mapping table, write the updated data into the obtained free page to obtain the transaction page, determine whether the current update transaction is completed, if it is determined that the current update transaction is completed, trigger the fourth update module, if it is determined that the current update transaction is not completed, trigger the first determination module; The fourth update module is used to modify the structured mark values of all data pages to be updated to the sixth preset value, modify the transaction mark values of all transaction pages to the second preset value, use all transaction pages as updated data pages, update the data area address mapping table according to the physical addresses of the updated data pages, and update the free area address mapping table according to the physical addresses of all data pages to be updated.
13. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 11.
14. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
15. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
Citation Information
Patent Citations
Spatial data engine and method applying management spatial data thereof
CN101639848A
Distributed flash memory transaction processing method
CN105005535A