Search

CN-122018778-A - Data storage method, device, computer equipment and storage medium

CN122018778ACN 122018778 ACN122018778 ACN 122018778ACN-122018778-A

Abstract

The application relates to a data storage method, a data storage device, computer equipment and a storage medium. The method comprises the steps of obtaining a data storage request, determining a target storage area and a data block index of a target data block from candidate storage areas of a memory according to the data storage request, determining a physical address of the target data block according to the data block index if the target storage area is a static data storage area, storing data to be stored into the target data block based on the physical address of the target data block, determining a starting write address in the dynamic data storage area based on the data block index if the target storage area is a dynamic data storage area, and storing the data to be stored into the target data block based on the starting write address. According to the scheme, the safety of data storage can be ensured, meanwhile, unnecessary operation codes are reduced in both dynamic storage and static storage, and the stability of data storage is improved.

Inventors

  • LU ZHICHAO

Assignees

  • 福思(杭州)智能科技有限公司

Dates

Publication Date
20260512
Application Date
20251204

Claims (10)

  1. 1. A method of data storage, comprising: Acquiring a data storage request, and determining a target storage area and a data block index of a target data block from candidate storage areas of a memory according to the data storage request, wherein the data storage request comprises data to be stored, the data block index of the target data block and a storage area identifier of the target storage area; If the target storage area is a static data storage area, determining a physical address of a target data block according to a data block index of the target data block, and storing data to be stored into the target data block based on the physical address of the target data block; If the target storage area is a dynamic data storage area, determining a start writing address in the dynamic data storage area based on a data block index of the target data block, and storing the data to be stored into the target data block based on the start writing address, wherein the start writing address is a latest storage address of a latest activated sector of last stored data in the dynamic data storage area.
  2. 2. The method of claim 1, wherein the static data storage area comprises two static data storage sectors, wherein the static data storage sectors comprise a static target sector and a static spare sector, wherein the static data storage sectors comprise static data blocks, wherein the configuration information of the static data blocks comprises data block indexes, universal unique identification codes, data block lengths, data block offset addresses, memory address pointers and an information table of the static data blocks, wherein the determining the physical addresses of the target data blocks according to the data block indexes of the target data blocks and storing the data to be stored into the target data blocks based on the physical addresses of the target data blocks comprises: determining configuration information of the target data block according to the data block index of the target data block, and determining data block address offset and data block length of the target data block according to the configuration information of the target data block; determining a data block base address of a target data block according to a sector base address of a static target sector in the static data storage area, the total length of state information of the static target sector and the data block address offset; determining whether stored data exists in the target data block; and if the stored data does not exist in the target data block, storing the data to be stored into the target data block based on the data block base address.
  3. 3. The method of claim 2, wherein determining whether stored data is present in the target data block further comprises: If the stored data exists in the target data block, determining whether the stored data is consistent with the data to be stored; And if the stored data is consistent with the data to be stored, determining that the data to be stored is stored in the target data block.
  4. 4. The method of claim 3, wherein determining if the stored data and the data to be stored are identical if the stored data exists in the target data block further comprises: If the stored data are inconsistent with the data to be stored, storing other data blocks except the target data block in the static target sector into a static standby sector in a static data storage area, and deleting the target data block and other data blocks in the static target sector; Constructing a target data block in the static standby sector based on the configuration information of the target data block, and storing the data to be stored into the target data block in the static standby sector; And taking the static standby sector stored in the data to be stored as a static target sector, and taking the static target sector for deleting the target data block and other data blocks in the static target sector as the static standby sector.
  5. 5. The method of claim 1, wherein the dynamic data storage area comprises at least four dynamic data storage sectors, wherein the dynamic data storage sectors comprise dynamic data blocks, wherein the configuration information of the dynamic data blocks comprises a data block index, a universal unique identification code, a data block length, a data block offset address, a memory address pointer, and an information table of the dynamic data blocks, wherein the determining a starting write address in the dynamic data storage area based on the data block index, and wherein the storing the data to be stored into a target data block based on the starting write address comprises: Reading the dynamic data block in the dynamic data storage area, and determining the latest storage address of the latest activated sector; Determining configuration information of a target data block based on the data block index of the target data block, determining the sector remaining length of the latest activated sector according to the sector length, the sector base address and the latest storage address of the latest activated sector, and determining whether the sector remaining length of the latest activated sector is larger than the data block length of the target data block; and if the sector remaining length of the latest activated sector is greater than the data block length of the target data block, taking the latest storage address of the latest activated sector in the latest activated sector as the initial writing address in the dynamic data storage area, and storing the data to be stored into the target data block based on the initial writing address and the configuration information of the target data block.
  6. 6. The method of claim 5, wherein determining configuration information of a target data block based on the data block index, determining a sector remaining length of a most recently activated sector based on a sector length of the most recently activated sector, a sector base address, and a most recently stored address, and determining whether the sector remaining length of the most recently activated sector is greater than a data block length of the target data block, further comprises: if the remaining length of the sector of the latest activated sector is smaller than or equal to the data block length of the target data block, the sector index of the next sector of the latest activated sector in the dynamic data storage area is pointed to a switching state, and the sector index of the latest activated sector is pointed to a data full state; Traversing a dynamic data storage sector in the dynamic data storage area, and storing the target data block to a sector next to the most recently activated sector; After the dynamic data storage sector in the dynamic data storage area is traversed, deleting the dynamic data block in the next two sectors of the latest activated sector, updating the sector state of the next two sectors of the latest activated sector to an erased state, and updating the sector state of the next two sectors of the latest activated sector to an in-use state.
  7. 7. The method of claim 5, wherein reading the dynamic data blocks in the dynamic data storage area comprises: Reading a dynamic data block from a recently activated sector based on a sector index of the recently activated sector, and determining a data block address of the read data block in the dynamic data storage area according to a sector base address and a sector storage capacity of the dynamic data storage sector in the dynamic data storage area; If the data block state information of the read data block is not null, reading the data block state information of the read data block based on the data block address; determining whether the fixed field of the read data block is consistent with a preset field value according to the data block state information of the read data block; If the fixed field of the read data block is consistent with a preset field value, determining the data block identity and the data block length of the read data block according to the data block state information of the read data block; Verifying the data block identity and the data block length of the read data block based on the configuration information of the read data block; If the verification is passed, reading the data of the read data block, and performing cyclic redundancy check on the data of the read data block; If the verification is passed, recording the sector index of the latest activated sector and the data block storage address of the read data block, determining the data block storage state of the read data block as an effective state, and copying the data in the read data block to a random access memory address space of the read data block; Determining whether a data block address of the read data block is less than a sector highest address of a most recently activated sector in the dynamic data storage area; if yes, determining that the dynamic data block in the latest activated sector is read, determining the sector index of the next sector of the latest activated sector according to the sector index of the latest activated sector and the sector number of the dynamic data storage sectors in the dynamic data storage area, and determining whether the dynamic data block in the next sector is read according to the sector index of the next sector; If yes, determining that the reading of the dynamic data block in the dynamic data storage area is completed.
  8. 8. A data storage device, the data storage device comprising: The system comprises a data storage request acquisition module, a data storage request acquisition module and a storage module, wherein the data storage request acquisition module is used for acquiring a data storage request and determining a target storage area and a data block index of a target data block from candidate storage areas of a memory according to the data storage request, wherein the data storage request comprises data to be stored, the data block index of the target data block and a storage area identifier of the target storage area; The static data storage module is used for determining the physical address of the target data block according to the data block index of the target data block if the target storage area is the static data storage area, and storing the data to be stored into the target data block based on the physical address of the target data block; And the dynamic data storage module is used for determining a start writing address in the dynamic data storage area based on the data block index of the target data block and storing the data to be stored into the target data block based on the start writing address if the target storage area is the dynamic data storage area, wherein the start writing address is the latest storage address of the latest activated sector for last data stored in the dynamic data storage area.
  9. 9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any one of claims 1 to 7 when the computer program is executed.
  10. 10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any one of claims 1 to 7.

Description

Data storage method, device, computer equipment and storage medium Technical Field The present application relates to the field of data storage technologies, and in particular, to a data storage method, apparatus, computer device, and storage medium. Background The MCU (Microcontroller Unit, micro control unit) in the vehicle controller needs to store EDR (EVENT DATA Recorder) information, configuration information, diagnostic information, and the like. Information sharing is required between the bootloader of the MCU and application, so that a storage protocol stack needs to be shared. The NVM (non-volatile memory) and the FEE (Flash EEPROM Emulation, flash analog EEPROM) of the automobile open system architecture have larger code quantity, more occupied memory resources, and fewer memory resources occupied by bootloader. When data at the MCU end is stored, a dynamic storage mode is often adopted, namely a data storage area is divided into at least two sectors, the data is circularly stored through the two sectors, the data storage mode is easy to cause abnormal power failure and data loss in the sector switching process, the sharing of data of bootloader and application is inconvenient to realize, and meanwhile, when the sectors are recombined, data blocks in all the sectors are required to be recombined, and the sector recombination efficiency is lower. Therefore, how to ensure the data security in the data storage process and improve the recombination efficiency of the data blocks in the sector is a problem to be solved. Disclosure of Invention In view of the foregoing, it is desirable to provide a data storage method, apparatus, computer device, and storage medium that can ensure data security during data storage and improve the reorganization efficiency of data blocks in a sector. In a first aspect, the present application provides a data storage method, the method comprising: Acquiring a data storage request, and determining a target storage area and a data block index of a target data block from candidate storage areas of a memory according to the data storage request, wherein the data storage request comprises data to be stored, the data block index of the target data block and a storage area identifier of the target storage area; If the target storage area is a static data storage area, determining a physical address of a target data block according to a data block index of the target data block, and storing data to be stored into the target data block based on the physical address of the target data block; If the target storage area is a dynamic data storage area, determining a start writing address in the dynamic data storage area based on the data block index, and storing the data to be stored into the target data block based on the start writing address, wherein the start writing address is the latest storage address of the latest activated sector for last data storage in the dynamic data storage area. In one embodiment, the static data storage area comprises two static data storage sectors, the static data storage sectors comprise static target sectors and static spare sectors, the static data storage sectors comprise static data blocks, configuration information of the static data blocks comprises data block indexes of the static data blocks, a universal unique identification code, data block lengths, data block offset addresses, memory address pointers and an information table, the physical addresses of the target data blocks are determined according to the data block indexes of the target data blocks, and data to be stored are stored into the target data blocks based on the physical addresses of the target data blocks, and the method comprises the following steps: determining configuration information of the target data block according to the data block index of the target data block, and determining data block address offset and data block length of the target data block according to the configuration information of the target data block; determining a data block base address of a target data block according to a sector base address of a static target sector in the static data storage area, the total length of state information of the static target sector and the data block address offset; determining whether stored data exists in the target data block; and if the stored data does not exist in the target data block, storing the data to be stored into the target data block based on the data block base address. In one embodiment, after determining whether the stored data exists in the target data block, the method further includes: If the stored data exists in the target data block, determining whether the stored data is consistent with the data to be stored; And if the stored data is consistent with the data to be stored, determining that the data to be stored is stored in the target data block. In one embodiment, if the stored data exists in the target data block, determining whether the